乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 82|回复: 1

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

[复制链接]

2

主题

3

帖子

1

银币

初来乍到

Rank: 1

铜币
11
发表于 2021-2-1 23:24:00 | 显示全部楼层 |阅读模式
  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.     End Select
  57.     '--------------------------------
  58.     Set offent = offobj
  59.     ReDim pt(UBound(offobj.Coordinates)) As Double
  60.     For I = 0 To UBound(pt) Step 3
  61.         pt(I) = offobj.Coordinate(I / 3)(0)
  62.         pt(I + 1) = offobj.Coordinate(I / 3)(1)
  63.     Next I
  64.     obj1.Delete
  65.     Set obj1 = Nothing
  66.     If de Then
  67.         offobj.Delete
  68.     End If
  69. End Function
  70. Public Function chkclose(SSet As AcadSelectionSet) As Boolean
  71.     chkclose = True
  72.     Dim pl As AcadObject
  73.     For I = 0 To SSet.Count - 1
  74.         Set pl = SSet.Item(I)
  75.         Select Case UCase(pl.ObjectName)
  76.             Case "ACDB3DPOLYLINE", "ACDB2DPOLYLINE"
  77.                 last = (UBound(pl.Coordinates) + 1) / 3 - 1
  78.             Case "ACDBPOLYLINE"
  79.                 last = (UBound(pl.Coordinates) + 1) / 2 - 1
  80.             Case "ACDBCIRCLE"
  81.                 last = -1
  82.         End Select
  83.         If last > 0 Then
  84.             If Not (pl.Closed Or (pl.Coordinate(0)(0) = pl.Coordinate(last)(0) And pl.Coordinate(0)(1) = pl.Coordinate(last)(1))) Then
  85.                 chkclose = False
  86.                 pl.color = acRed
  87.                 pl.Highlight True
  88.             End If
  89.         End If
  90.     Next I
  91. End Function
  92. Sub trim()
  93.     Dim ptt(0 To 7) As Double
  94.     pt1 = ThisDrawing.Utility.GetPoint(, " ?????????????:")
  95.     pt2 = ThisDrawing.Utility.GetCorner(pt1, " ?????????????:")
  96.     ptt(0) = pt1(0)
  97.     ptt(1) = pt1(1)
  98.     ptt(2) = pt1(0)
  99.     ptt(3) = pt2(1)
  100.     ptt(4) = pt2(0)
  101.     ptt(5) = pt2(1)
  102.     ptt(6) = pt2(0)
  103.     ptt(7) = pt1(1)
  104.     Set plineObj = ThisDrawing.ModelSpace.AddLightWeightPolyline(ptt)
  105.     plineObj.Closed = True
  106.        Dim SSet1 As AcadSelectionSet
  107.     For Each SSet1 In ThisDrawing.SelectionSets
  108.         If SSet1.Name = "SS2" Then
  109.             ThisDrawing.SelectionSets.Item("SS2").Delete
  110.             Exit For
  111.         End If
  112.     Next
  113.     Set SSet1 = ThisDrawing.SelectionSets.Add("SS2")
  114.     Dim keyWord As String
  115.    
  116.    
  117.     '??????????????
  118.     Dim ft() As Integer
  119.     Dim fd() As Variant
  120.     ReDim ft(0) As Integer
  121.     ReDim fd(0) As Variant
  122.     ft(0) = 0
  123.     fd(0) = "polyline,lwpolyline,circle"
  124.    
  125.         SSet1.Select acSelectionSetLast, pt1, pt2, ft, fd
  126.    
  127.     If SSet1.Count = 0 Then
  128.         MsgBox "δ???????", vbCritical, "??????"
  129.         Exit Sub
  130.     End If
  131.     If Not chkclose(SSet1) Then
  132.         MsgBox "?????????в???????Σ?" & vbCr & "???飬?????????г???", vbCritical, "?????"
  133.         
  134.         Exit Sub
  135.     End If
  136.    
  137.     ThisDrawing.StartUndoMark
  138.     Dim offobj As AcadEntity
  139.    
  140.    
  141.     Dim off As Double
  142.     off = 0.1
  143.     Dim pt() As Double
  144.     ThisDrawing.Regen acActiveViewport
  145.     'ThisDrawing.Application.ZoomExtents
  146.    
  147.     Dim strcom As String
  148.     ThisDrawing.SetVariable "modemacro", "????????????????????..."
  149.     '??????ж??????????????????
  150.     ThisDrawing.SendCommand "trim "
  151.     For I = 0 To SSet1.Count - 1
  152.         ThisDrawing.SendCommand axEnt2lspEnt(SSet1.Item(I)) & vbCr
  153.         Set offobj = offent(SSet1.Item(I), off, pt(), False)
  154.         ThisDrawing.SendCommand axEnt2lspEnt(offobj) & vbCr
  155.     Next I
  156.     ThisDrawing.SendCommand vbCr
  157.     '????????????????????????
  158.     For I = 0 To SSet1.Count - 1
  159.         Set offobj = offent(SSet1.Item(I), off / 2, pt(), True)
  160.         For j = 0 To UBound(pt) Step 3
  161.             strcom = strcom & pt(j)
  162.             strcom = strcom & "," & pt(j + 1) & vbCr
  163.         Next j
  164.         strcom = strcom & pt(0)
  165.         strcom = strcom & "," & pt(1) & vbCr
  166.         strcom = strcom & Chr(9)
  167.     Next I
  168.    
  169.     '???????????????????
  170.     Dim sc() As String
  171.     sc = Split(strcom, Chr(9))
  172.     '------------------------------------------------
  173.    
  174.    
  175.         ThisDrawing.SetVariable "modemacro", "."
  176.         ThisDrawing.SetVariable "modemacro", "??????е?" & j & "?β???..."
  177.         For I = 0 To UBound(sc) - 1
  178.             DoEvents
  179.             ThisDrawing.SendCommand "f " & sc(I) & vbCr
  180.         Next I
  181. '    GoTo begindel
  182.     SSet1.Clear
  183.     ReDim ft(0) As Integer
  184.     ReDim fd(0) As Variant
  185.     ft(0) = 0: fd(0) = "polyline,lwpolyline,circle"
  186.     For I = 0 To UBound(sc) - 1
  187.         pp = Split(sc(I), vbCr)
  188.         n = -1
  189.         For k = 0 To UBound(pp) - 1
  190.             temp = Split(pp(k), ",")
  191.             n = n + 3
  192.             ReDim Preserve pt(n) As Double
  193.             pt(n - 2) = temp(0)
  194.             pt(n - 1) = temp(1)
  195.         Next k
  196.         Set temp = Nothing
  197.         SSet1.SelectByPolygon acSelectionSetFence, pt, ft, fd
  198.         last = SSet1.Count
  199.         Dim lp As Integer
  200.         n = 0
  201.         'lp = 0
  202.         While SSet1.Count  0
  203.             lp = lp + 1
  204.             ThisDrawing.SetVariable "modemacro", "."
  205.             ThisDrawing.SetVariable "modemacro", "??????е?" & lp & "?β???..."
  206.             last = SSet1.Count
  207.             ThisDrawing.SendCommand "f " & sc(I) & vbCr
  208.             SSet1.Clear
  209.             If last = 0 Then GoTo nnext
  210.             SSet1.SelectByPolygon acSelectionSetFence, pt, ft, fd
  211.             If last = SSet1.Count Then
  212.                 n = n + 1
  213.             End If
  214.             If n = 4 Then
  215.                 GoTo nnext
  216.             End If
  217.         Wend
  218. nnext:
  219.     Next I
  220.    
  221. begindel:
  222.     Set offobj = Nothing
  223.     ReDim pt(0) As Double
  224.     strcom = ""
  225.     Set pp = Nothing
  226.     SSet1.Clear
  227.     ThisDrawing.SendCommand vbCr
  228.    
  229.     ThisDrawing.Utility.InitializeUserInput 0, "1 2"
  230.    
  231.     keyWord = ThisDrawing.Utility.GetKeyword(vbCrLf & "?ü??????????1,?ü????????2 (1/2): ")
  232.    
  233.     If keyWord = "" Then keyWord = "1"
  234.    
  235.     '??????????
  236.     ThisDrawing.SendCommand "e "
  237.     '        '??????
  238.     If keyWord = "1" Then
  239.         sendcom = "wp "
  240.         For I = 0 To UBound(sc) - 1
  241.             ThisDrawing.SendCommand sendcom & sc(I) & vbCr
  242.         Next I
  243.         
  244.         '???????
  245.     ElseIf keyWord = "2" Then
  246.         sendcom = "r wp "
  247.         ThisDrawing.SendCommand "all "
  248.         For I = 0 To UBound(sc) - 1
  249.             ThisDrawing.SendCommand sendcom & sc(I) & vbCr
  250.         Next I
  251.     End If
  252.    
  253.     ThisDrawing.SendCommand vbCr
  254.     ThisDrawing.EndUndoMark
  255.   
  256. End Sub
以上是批量裁剪功能,参考某大神编写的,请问大神们如何把框选裁剪前的数据先复制粘贴到新建文件里面再实行自动裁剪?
回复

使用道具 举报

15

主题

112

帖子

8

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
171
发表于 2021-4-24 03:56:00 | 显示全部楼层

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

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-12 23:24 , Processed in 0.449691 second(s), 67 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表