乐筑天下

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

[编程交流] VBA - 'Splinedit' eq

[复制链接]

13

主题

51

帖子

38

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 23:26:46 | 显示全部楼层
Thanks guys, I greatly appreciate this.
 
Below is the code I've written so far. If you run through for one loop of the FOR loop, it works fine (check the numeral '5' on the attached example.dwg before and after you run the code), but when you run through a second time I get a catastrophic failure at line "SET ADDITEM(0) = SSET (X1)" and I'm not sure why. If you re-run through the first loop again, you'll error immediately after "THISDRAWING.SENDCOMMAND" because the selected spline is a closed loop.
 
  1. Sub JoinSplines()Dim SSet As AcadSelectionSetDim oSSetGroup As AcadGroupDim sGRName As StringDim FilterType(0) As IntegerDim FilterData(0) As VariantDim X1 As IntegerDim AddItem() As AcadEntityOn Error Resume NextIf ThisDrawing.SelectionSets.Item("SSet") Is Nothing Then   Set SSet = ThisDrawing.SelectionSets.Add("SSet")Else   ThisDrawing.SelectionSets.Item("SSet").Clear   Set SSet = ThisDrawing.SelectionSets("SSet")End IfOn Error GoTo 0Err.ClearFilterType(0) = 0FilterData(0) = "Spline"SSet.Select acSelectionSetAll, , , FilterType, FilterDataReDim AddItem(0) As AcadEntityFor X1 = 1 To SSet.Count   Set oSSetGroup = ThisDrawing.Groups.Add("SG")   sGRName = oSSetGroup.Name     [color="red"] ''CATASTROPHIC FAILURE HERE[/color]   Set AddItem(0) = SSet(X1)      oSSetGroup.AppendItems AddItem      [color="red"]'''NEED TO END ANY, AND ALL EXISTING COMMANDS BEFORE PROCEEDING[/color]   On Error Resume Next   ThisDrawing.SendCommand "splinedit" + vbCr + "G" + vbCr + sGRName + vbCr + "J" + vbCr + _                           "all" + vbCr + vbCr + vbCr   If Not Err Is Nothing Then       ThisDrawing.SendCommand "!(command)" & vbCr [color="red"]'''NEED TO END CURRENT COMMAND HERE.[/color]       Err.Clear   End If   On Error GoTo 0      oSSetGroup.Delete   ReDim AddItem(X1) As AcadEntity   NextEnd Sub
 
The code sample you posted, RenderMan, works well if the loop contains only splines, but the code I've posted above works for loops containing loops, lines and arcs like the attached file (example.dwg). The code will process text loops like this almost exclusively. Once it's done joining splines, it will join any remaining polylines.
 
Thanks again.
Example.dwg
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 23:33:27 | 显示全部楼层
AutoCAD 2012 can use the standard JOIN command (i.e., not through SPLINEDIT) to join both splines and non splines into one large composite (See returned sample).  So, depending on what the end result needs to be, perhaps this variation on your posted code would do.  

I can’t test it myself because my install of AutoCAD 2012 is 64 bit, with which VBA does not play nice.

  1. Sub JoinSplines()   ' This example adds objects to a selection set by prompting the user   ' to select ones to add.      ' Create the selection set   Dim ssetObj As AcadSelectionSet   On Error Resume Next   ThisDrawing.SelectionSets.Item("TEST_SSET").Delete   On Error GoTo 0   Set ssetObj = ThisDrawing.SelectionSets.Add("TEST_SSET")   Dim mode As Integer   Dim pointsArray(0 To 11) As Double   mode = acSelectionSetCrossingPolygon  'I just hardcoded a rectangle size to fit.  May want to use extmin and extmax   pointsArray(0) = 0#: pointsArray(1) = 0#: pointsArray(2) = 0#   pointsArray(3) = 950#: pointsArray(4) = 0#: pointsArray(5) = 0#   pointsArray(6) = 950#: pointsArray(7) = 420#: pointsArray( = 0#   pointsArray(9) = 0#: pointsArray(10) = 420#: pointsArray(11) = 0#      ssetObj.SelectByPolygon mode, pointsArray   ThisDrawing.SendCommand "JOIN" & vbCr & "Previous" & vbCr & vbCr   End Sub
Example_2012.dwg
回复

使用道具 举报

13

主题

51

帖子

38

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 23:37:54 | 显示全部楼层
Oh damn... that would be helpful... unfortunately we won't be rolling out 2012 here for quite some time (if at all).
 
Either way... I think I got it sorted...
 
  1. Sub JoinSplinesOnDWG()Dim SSet As AcadSelectionSetDim oSSetGroup As AcadGroupDim sGRName As StringDim FilterType(0) As IntegerDim FilterData(0) As VariantDim X1 As IntegerDim SplCountLive As IntegerDim AddItem() As AcadEntityDim acadDoc As AcadDocumentSet acadDoc = ThisDrawingOn Error Resume NextIf ThisDrawing.SelectionSets.Item("SSet") Is Nothing Then   Set SSet = ThisDrawing.SelectionSets.Add("SSet")Else   ThisDrawing.SelectionSets.Item("SSet").Clear   Set SSet = ThisDrawing.SelectionSets("SSet")End IfOn Error GoTo 0Err.ClearFilterType(0) = 0FilterData(0) = "Spline"ReDim AddItem(0) As AcadEntitySSet.Select acSelectionSetAll, , , FilterType, FilterDataSplCountLive = SSet.CountX1 = 0Do Until X1 = SplCountLive   X1 = X1 + 1   Set oSSetGroup = ThisDrawing.Groups.Add("SG")   sGRName = oSSetGroup.Name   Set AddItem(0) = SSet(X1)      oSSetGroup.AppendItems AddItem      On Error Resume Next   If AddItem(0).Closed = False Then       ThisDrawing.SendCommand "splinedit" + vbCr + "G" + vbCr + sGRName + vbCr + "J" + vbCr + _                               "all" + vbCr + vbCr + vbCr   End If   If Not Err = 0 Then       ThisDrawing.SendCommand "!(command)" & vbCr       Err.Clear   End If   On Error GoTo 0      oSSetGroup.Delete   SSet.Clear   SSet.Select acSelectionSetAll, , , FilterType, FilterData   SplCountLive = SSet.CountLoopEnd Sub
 
 
Next question... I found a good site yesterday explaining how to use multiple filters in your selection sets... But I can't find it again...
 
Here's what I've got...
 
 
  1. Dim FilterType(1) As IntegerDim FilterData(1) As VariantFilterType(0) = 0FilterData(0) = "Arc"FilterType(1) = 0FilterData(1) = "Line"SSet.Select acSelectionSetAll, , , FilterType, FilterData
 
Unfortunately, this returns 0 items... but if I run either filter type separately, then I get plenty of objects returned...
 
What have I missed?
回复

使用道具 举报

13

主题

51

帖子

38

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 23:39:33 | 显示全部楼层
Found it...
 
http://www.kxcad.net/autodesk/autocad/Autodesk_AutoCAD_ActiveX_and_VBA_Developer_Guide/ws1a9193826455f5ff1a32d8d10ebc6b7ccc-6c11.htm
回复

使用道具 举报

10

主题

973

帖子

909

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
118
发表于 2022-7-6 23:44:23 | 显示全部楼层
For that particular data type items can be strung together.  Does this work any different:
 
  1. Dim FilterType(0) As IntegerDim FilterData(0) As VariantFilterType(0) = 0FilterData(0) = "Arc,Line"SSet.Select acSelectionSetAll, , , FilterType, FilterData
回复

使用道具 举报

13

主题

51

帖子

38

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2022-7-6 23:47:43 | 显示全部楼层
Oh damn... that simple... I'll have to give that a shot tomorrow at work.
 
I got the method mentioned on that kxcad.net website to work.. so it's all good... now when I run both bits of code, it joins all splines together, then all lines and arcs together as polylines...
 
Next episode, we hatch and export... then add the whole lot to the Inventor code I wrote earlier.
 
Thanks heaps for your help.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-1-31 17:46 , Processed in 0.215530 second(s), 62 queries .

© 2020-2025 乐筑天下

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