rjtaylor96 Posted October 29, 2020 Posted October 29, 2020 Hi there, im pretty new to coding in Visual Basic for autocad, i was wondering if anyone could help me with this code im trying to develop. Pretty much you select a group of 3d solids and the code automatically draws a sphere at the centroid of those objects. So far i have gotten my code to only show the centroid of one of the objects and not the groups centroid i know what part of code is the issue im just not really sure how to solve it Private Sub CommandButton1_Click() Me.Hide Dim R As Double Dim OCG As Variant Dim objEnt As Object Dim objSset As AcadSelectionSet Dim objDraw As AcadCircle Dim FilterType(0) As Integer Dim FilterData(0) As Variant On Error Resume Next FilterType(0) = 0 FilterData(0) = "3dsolid" Set objSset = ThisDrawing.SelectionSets.Add("ss") Me.Hide objSset.SelectOnScreen FilterType, FilterData For Each objEnt In objSset --- this part is the issue as it changes OCG to whatever object it is going through in the loop OCG = objEnt.Centroid Next With ThisDrawing.Utility R = 50 End With Set objDraw = ThisDrawing.ModelSpace.AddSphere(OCG, R) objDraw.Update MsgBox "X = " & OCG(0) & " Y = " & OCG(1) & " Z = " & OCG(2) & "." -- this will eventually be removed, this double checks atm to see if the code is showing the right centroid objSset.Delete any help would be appreciated Quote
rjtaylor96 Posted October 29, 2020 Author Posted October 29, 2020 Private Sub CommandButton1_Click() Me.Hide Dim R As Double Dim OCG As Variant Dim objEnt As Object Dim objSset As AcadSelectionSet Dim objDraw As AcadCircle Dim FilterType(0) As Integer Dim FilterData(0) As Variant On Error Resume Next FilterType(0) = 0 FilterData(0) = "3dsolid" Set objSset = ThisDrawing.SelectionSets.Add("ss") Me.Hide objSset.SelectOnScreen FilterType, FilterData For Each objEnt In objSset OCG = objEnt.Centroid Next With ThisDrawing.Utility R = 50 End With Set objDraw = ThisDrawing.ModelSpace.AddSphere(OCG, R) objDraw.Update MsgBox "X = " & OCG(0) & " Y = " & OCG(1) & " Z = " & OCG(2) & "." objSset.Delete should of added the code bb codes sorry Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.