I need to connect 2 splines through a macro

I need to connect 2 splines through a macro

dmitryi2022
Explorer Explorer
497 Views
5 Replies
Message 1 of 6

I need to connect 2 splines through a macro

dmitryi2022
Explorer
Explorer

Hi all! Tell me please, I need to connect 2 splines through a macro, by googling I collected this for tests:

Dim ssetObj As AcadSelectionSet

Set sset = ThisDrawing.SelectionSets

Dim acadobj As AcadObject

Dim objname As String

For Each ssetObj In sset

If UCase(ssetObj.Name) = "TEST" Then

sset.Item("TEST").Delete

Exit For

End If

Next

 

Set ssetObj = ThisDrawing.SelectionSets.Add("TEST")

ssetObj.Select acSelectionSetAll

 

' there is an error

ThisDrawing.SendCommand "_SPLINEDIT" & vbCr & ssetObj.Item(0) & vbCr & "join" & vbCr & ssetObj.Item(1) & vbCr & vbCr

 

I have two splines in total, I wanted to combine them, but the error is on the last line (obj doesnt support this property or method)
If manually, the commands take turns, then everything is fine. These splines are two quarters of a circle, but separate.
The splines are:
SPLINE Layer: "0"
Space: Model space
Handle = 4a2
Length: 15.7102
Order: 4
Properties: Planar, Non-Rational, Non-Periodic

I'm new to AutoCAD, I would like to understand, thanks!

0 Likes
498 Views
5 Replies
Replies (5)
Message 2 of 6

seabrahenrique
Advocate
Advocate

Hello

 

Instead:

 

 

ThisDrawing.SendCommand "_SPLINEDIT" & vbCr & ssetObj.Item(0) & vbCr & "join" & vbCr & ssetObj.Item(1) & vbCr & vbCr

 

 

Try this:

 

 

ThisDrawing.SendCommand "_SPLINEDIT (handent """ & ssetObj.Item(0).Handle & """) " & "JOIN" & vbCr & "(handent """ & ssetObj.Item(1).Handle & """)" & vbCr & vbCr & vbCr

 

 

Inside your code, u can acess objects by "ssetObj.Item(0)" for example... But if you use AutoCAD comand line, u must to use something like the "hadent" and handle of object.

 

Is there others ways to do this purpose, but folowing your line, i guess this is the solution.

 

I hope that help u

Message 3 of 6

dmitryi2022
Explorer
Explorer
seabrahenrique,
Thanks a lot, you helped me a lot!!
You wrote about other ways, can you please show?
Is there a command that concatenates all elements (objects) of an array in one time? Or do I need to loop through all the elements? Thank you!
0 Likes
Message 4 of 6

seabrahenrique
Advocate
Advocate

Maybe in that way:

 

1) Colect the control points of the first spiline;

2) Collect the control points of the second spiline;

3) Put all of then in a Array, and use ThisDrawing.ModelSpace.AddSpline to create a new SPILINE.

 

I have never work with spilines, but thinking better, because they have some angles, i guess the more fast and pratical way is in fact my last sugestion, with the "handent" in comand line.

 

Remember mark as solution if one of them really help u 🙂

Message 5 of 6

Ed__Jobe
Mentor
Mentor

Here are some functions I wrote for such a situation.

 

 


Public Function Ent2lspEnt(entObj As AcadEntity) As String
    'Designed to work with SendCommand, which can't pass objects.
    'This gets an objects handle and converts it to a string
    'of lisp commands that returns an entity name when run in SendCommand.
    Dim entHandle As String
    
    entHandle = entObj.Handle
    Ent2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
End Function

Public Function SS2lspEnt(ss As AcadSelectionSet, index As Integer) As String
    'Designed to work with SendCommand, which can't pass objects.
    'This gets an objects handle and converts it to a string
    'of lisp commands that returns an entity name when run in SendCommand.
    Dim entHandle As String
    
    entHandle = ss(index).Handle
    SS2lspEnt = "(handent " & Chr(34) & entHandle & Chr(34) & ")"
End Function

 

 

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 6 of 6

dmitryi2022
Explorer
Explorer

I tried first, collect the coordinates and use .AddSpline, but the 2, 3 argument of this function uses tangents... I don't understand how to manage them.
I found another way for this:
1) Created spline (2 points) .AddSpline and both tangents = 0
2) After creating a spline for each point .SetControlPoint x y (mm)
And so for several splines
3) Well, here I would like to combine splines (I think there is already a solution in this post above)

It will all be in a cycle

Thanks for answers!

0 Likes