明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1081|回复: 1

批量裁剪后如何复制粘贴到原坐标

[复制链接]
发表于 2021-2-1 23:24:58 | 显示全部楼层 |阅读模式
  1. Public Function axEnt2lspEnt(entObj As AcadEntity) As String
  2.     Dim entHandle As String
  3.     entHandle = entObj.Handle
  4.     axEnt2lspEnt = "(handent" & Chr(34) & entHandle & Chr(34) & ")"
  5. End Function
  6. Public Function offent(obj As AcadEntity, off As Double, pt() As Double, de As Boolean) As AcadEntity
  7.     Const pi = 3.1415926
  8.     'obj??????????off???????????????pt()???????????????????,de ???????????????
  9.     '???obj????????????????????????????????????
  10.     Dim obj1 As AcadPolyline
  11.     Dim pl As AcadPolyline
  12.     Dim cr As AcadCircle
  13.     Select Case UCase(obj.ObjectName)
  14.         Case "ACDB3DPOLYLINE", "ACDB2DPOLYLINE"

  15.             ReDim pt(UBound(obj.Coordinates)) As Double
  16.             For I = 0 To UBound(pt) Step 3
  17.                 pt(I) = obj.Coordinate(I / 3)(0)
  18.                 pt(I + 1) = obj.Coordinate(I / 3)(1)
  19.             Next I
  20.             teml = obj.Layer
  21.             temc = obj.Closed

  22.         Case "ACDBPOLYLINE"
  23.             ReDim pt(((UBound(obj.Coordinates) + 1) / 2) * 3 - 1) As Double
  24.             For I = 0 To UBound(pt) Step 3
  25.                 pt(I) = obj.Coordinate((I) / 3)(0)
  26.                 pt(I + 1) = obj.Coordinate((I) / 3)(1)
  27.             Next I
  28.             teml = obj.Layer
  29.             temc = obj.Closed
  30.         Case "ACDBCIRCLE"
  31.             Set cr = obj
  32.             Dim pp As Double
  33.             pp = cr.radius
  34.             ReDim pt(359 * 3 + 2) As Double
  35.             For I = 0 To 359
  36.                 pt(I * 3) = cr.center(0) + Cos(I * pi / 180) * cr.radius
  37.                 pt(I * 3 + 1) = cr.center(1) + Sin(I * pi / 180) * cr.radius
  38.                 pt(I * 3 + 2) = 0
  39.             Next I
  40.             teml = obj.Layer
  41.             temc = True
  42.     End Select
  43.     Set obj1 = ThisDrawing.ModelSpace.AddPolyline(pt)
  44.     obj1.Layer = teml
  45.     obj1.Closed = temc

  46.     '---------------------------------
  47.     Dim offobj As AcadEntity
  48.     Select Case off
  49.         Case Is > 0
  50.             off1 = obj1.Offset(off)
  51.             If off1(0).Area < obj1.Area Then
  52.                 off1(0).Delete
  53.                 off1 = obj1.Offset(-1 * off)
  54.             End If
  55.             Set offobj = off1(0)
  56.         Case Is < 0
  57.             off1 = obj1.Offset(off)
  58.             If off1(0).Area > obj1.Area Then
  59.                 off1(0).Delete
  60.                 off1 = obj1.Offset(-1 * off)
  61.             End If
  62.             Set offobj = off1(0)
  63.     End Select
  64.     '--------------------------------
  65.     Set offent = offobj
  66.     ReDim pt(UBound(offobj.Coordinates)) As Double
  67.     For I = 0 To UBound(pt) Step 3
  68.         pt(I) = offobj.Coordinate(I / 3)(0)
  69.         pt(I + 1) = offobj.Coordinate(I / 3)(1)
  70.     Next I
  71.     obj1.Delete
  72.     Set obj1 = Nothing
  73.     If de Then
  74.         offobj.Delete
  75.     End If
  76. End Function
  77. Public Function chkclose(SSet As AcadSelectionSet) As Boolean
  78.     chkclose = True
  79.     Dim pl As AcadObject

  80.     For I = 0 To SSet.Count - 1
  81.         Set pl = SSet.Item(I)
  82.         Select Case UCase(pl.ObjectName)
  83.             Case "ACDB3DPOLYLINE", "ACDB2DPOLYLINE"
  84.                 last = (UBound(pl.Coordinates) + 1) / 3 - 1
  85.             Case "ACDBPOLYLINE"
  86.                 last = (UBound(pl.Coordinates) + 1) / 2 - 1
  87.             Case "ACDBCIRCLE"
  88.                 last = -1
  89.         End Select
  90.         If last > 0 Then
  91.             If Not (pl.Closed Or (pl.Coordinate(0)(0) = pl.Coordinate(last)(0) And pl.Coordinate(0)(1) = pl.Coordinate(last)(1))) Then
  92.                 chkclose = False
  93.                 pl.color = acRed
  94.                 pl.Highlight True
  95.             End If
  96.         End If

  97.     Next I
  98. End Function

  99. Sub trim()

  100.     Dim ptt(0 To 7) As Double
  101.     pt1 = ThisDrawing.Utility.GetPoint(, " ?????????????:")
  102.     pt2 = ThisDrawing.Utility.GetCorner(pt1, " ?????????????:")
  103.     ptt(0) = pt1(0)
  104.     ptt(1) = pt1(1)
  105.     ptt(2) = pt1(0)
  106.     ptt(3) = pt2(1)
  107.     ptt(4) = pt2(0)
  108.     ptt(5) = pt2(1)
  109.     ptt(6) = pt2(0)
  110.     ptt(7) = pt1(1)
  111.     Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptt)

  112.     plineObj.Closed = True
  113.        Dim SSet1 As AcadSelectionSet
  114.     For Each SSet1 In ThisDrawing.SelectionSets
  115.         If SSet1.Name = "SS2" Then
  116.             ThisDrawing.SelectionSets.Item("SS2").Delete
  117.             Exit For
  118.         End If
  119.     Next
  120.     Set SSet1 = ThisDrawing.SelectionSets.Add("SS2")
  121.     Dim keyWord As String
  122.    

  123.    
  124.     '??????????????
  125.     Dim ft() As Integer
  126.     Dim fd() As Variant
  127.     ReDim ft(0) As Integer
  128.     ReDim fd(0) As Variant
  129.     ft(0) = 0
  130.     fd(0) = "polyline,lwpolyline,circle"
  131.    

  132.         SSet1.Select acSelectionSetLast, pt1, pt2, ft, fd
  133.    
  134.     If SSet1.Count = 0 Then
  135.         MsgBox "δ???????", vbCritical, "??????"
  136.         Exit Sub
  137.     End If
  138.     If Not chkclose(SSet1) Then
  139.         MsgBox "?????????в???????Σ?" & vbCr & "???飬?????????г???", vbCritical, "?????"
  140.         
  141.         Exit Sub
  142.     End If
  143.    
  144.     ThisDrawing.StartUndoMark
  145.     Dim offobj As AcadEntity
  146.    
  147.    
  148.     Dim off As Double
  149.     off = 0.1

  150.     Dim pt() As Double

  151.     ThisDrawing.Regen acActiveViewport
  152.     'ThisDrawing.Application.ZoomExtents
  153.    
  154.     Dim strcom As String

  155.     ThisDrawing.SetVariable "modemacro", "????????????????????..."

  156.     '??????ж??????????????????

  157.     ThisDrawing.SendCommand "trim "
  158.     For I = 0 To SSet1.Count - 1
  159.         ThisDrawing.SendCommand axEnt2lspEnt(SSet1.Item(I)) & vbCr
  160.         Set offobj = offent(SSet1.Item(I), off, pt(), False)
  161.         ThisDrawing.SendCommand axEnt2lspEnt(offobj) & vbCr
  162.     Next I
  163.     ThisDrawing.SendCommand vbCr
  164.     '????????????????????????
  165.     For I = 0 To SSet1.Count - 1
  166.         Set offobj = offent(SSet1.Item(I), off / 2, pt(), True)
  167.         For j = 0 To UBound(pt) Step 3
  168.             strcom = strcom & pt(j)
  169.             strcom = strcom & "," & pt(j + 1) & vbCr
  170.         Next j
  171.         strcom = strcom & pt(0)
  172.         strcom = strcom & "," & pt(1) & vbCr
  173.         strcom = strcom & Chr(9)
  174.     Next I
  175.    
  176.     '???????????????????
  177.     Dim sc() As String
  178.     sc = Split(strcom, Chr(9))
  179.     '------------------------------------------------
  180.    
  181.    
  182.         ThisDrawing.SetVariable "modemacro", "."
  183.         ThisDrawing.SetVariable "modemacro", "??????е?" & j & "?β???..."
  184.         For I = 0 To UBound(sc) - 1
  185.             DoEvents
  186.             ThisDrawing.SendCommand "f " & sc(I) & vbCr
  187.         Next I
  188. '    GoTo begindel

  189.     SSet1.Clear
  190.     ReDim ft(0) As Integer
  191.     ReDim fd(0) As Variant
  192.     ft(0) = 0: fd(0) = "polyline,lwpolyline,circle"
  193.     For I = 0 To UBound(sc) - 1
  194.         pp = Split(sc(I), vbCr)
  195.         n = -1
  196.         For k = 0 To UBound(pp) - 1
  197.             temp = Split(pp(k), ",")
  198.             n = n + 3
  199.             ReDim Preserve pt(n) As Double
  200.             pt(n - 2) = temp(0)
  201.             pt(n - 1) = temp(1)
  202.         Next k
  203.         Set temp = Nothing
  204.         SSet1.SelectByPolygon acSelectionSetFence, pt, ft, fd
  205.         last = SSet1.Count
  206.         Dim lp As Integer
  207.         n = 0
  208.         'lp = 0
  209.         While SSet1.Count <> 0
  210.             lp = lp + 1
  211.             ThisDrawing.SetVariable "modemacro", "."
  212.             ThisDrawing.SetVariable "modemacro", "??????е?" & lp & "?β???..."
  213.             last = SSet1.Count
  214.             ThisDrawing.SendCommand "f " & sc(I) & vbCr
  215.             SSet1.Clear
  216.             If last = 0 Then GoTo nnext
  217.             SSet1.SelectByPolygon acSelectionSetFence, pt, ft, fd
  218.             If last = SSet1.Count Then
  219.                 n = n + 1
  220.             End If
  221.             If n = 4 Then
  222.                 GoTo nnext
  223.             End If
  224.         Wend
  225. nnext:
  226.     Next I
  227.    
  228. begindel:
  229.     Set offobj = Nothing
  230.     ReDim pt(0) As Double
  231.     strcom = ""
  232.     Set pp = Nothing
  233.     SSet1.Clear
  234.     ThisDrawing.SendCommand vbCr
  235.    
  236.     ThisDrawing.Utility.InitializeUserInput 0, "1 2"
  237.    
  238.     keyWord = ThisDrawing.Utility.GetKeyword(vbCrLf & "?ü??????????1,?ü????????2 (1/2): ")
  239.    
  240.     If keyWord = "" Then keyWord = "1"
  241.    
  242.     '??????????
  243.     ThisDrawing.SendCommand "e "

  244.     '        '??????
  245.     If keyWord = "1" Then

  246.         sendcom = "wp "

  247.         For I = 0 To UBound(sc) - 1
  248.             ThisDrawing.SendCommand sendcom & sc(I) & vbCr
  249.         Next I
  250.         
  251.         '???????
  252.     ElseIf keyWord = "2" Then
  253.         sendcom = "r wp "

  254.         ThisDrawing.SendCommand "all "
  255.         For I = 0 To UBound(sc) - 1
  256.             ThisDrawing.SendCommand sendcom & sc(I) & vbCr
  257.         Next I
  258.     End If
  259.    

  260.     ThisDrawing.SendCommand vbCr
  261.     ThisDrawing.EndUndoMark
  262.   
  263. End Sub





以上是批量裁剪功能,参考某大神编写的,请问大神们如何把框选裁剪前的数据先复制粘贴到新建文件里面再实行自动裁剪?
发表于 2021-4-24 03:56:12 | 显示全部楼层
本帖最后由 KO你 于 2021-12-30 06:06 编辑

方法1:
快捷键  cv1  粘贴到原坐标
(defun c:cv1 () (command"pasteorig"))
方法2:
可以试试先“Ctrl+C(复制)”,然后输入“Alt+E+D”组合键CAD默认的,没必要去编
方法3:
也可以命令copybase带基点复制输入坐标0,0   粘贴时也输入坐标0,0




您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 04:57 , Processed in 0.164407 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表