Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Insert snaped to line sketch symbol

hieut1392
Enthusiast

Insert snaped to line sketch symbol

hieut1392
Enthusiast
Enthusiast

 

 

I am writing a macro that inserts the sketch symbol, but after inserting the symbol does not stick to the line, it can be dragged anywhere. I want it to stick to the line. Can you help me?

 

hieut1392_0-1675481385625.png

 

Sub TEST()

Dim oDoc As DrawingDocument
Set oDoc = ThisApplication.ActiveDocument

Dim oSheet As sheet
Set oSheet = oDoc.ActiveSheet

Dim xPos As Double
Dim yPos As Double

Dim oLine As Object
Set oLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Pick a line")

xPos = oLine.StartPoint.x
yPos = oLine.StartPoint.y

Dim oSketchedSymbolDef As SketchedSymbolDefinition
Set oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item("MySymbol")

Dim oTG As TransientGeometry
Set oTG = ThisApplication.TransientGeometry

Dim oSketchedSymbol As SketchedSymbol
Set oSketchedSymbol = oSheet.SketchedSymbols.Add _
                        (oSketchedSymbolDef, oTG.CreatePoint2d(xPos, yPos), 0, 1)

End Sub

 

 

0 Likes
Reply
Accepted solutions (1)
376 Views
2 Replies
Replies (2)

JelteDeJong
Mentor
Mentor
Accepted solution

You should have a look at the method "SketchedSymbols.AddWithLeader". (In the help files there is also an example.)

Suppose you created the sketch symbol (with a leader). Then you can hide (not delete) the leader with the property LeaderVisible.

SketchedSymbol.LeaderVisible = False

 

Jelte de Jong
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.

EESignature


Blog: hjalte.nl - github.com

0 Likes

hieut1392
Enthusiast
Enthusiast

thanks for your helping. my code is below.

 

Sub XXX(name As String, rotary As String)

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oActiveSheet As sheet
Set oActiveSheet = oDrawDoc.ActiveSheet

Repeat:

Dim oLine As Object
Set oLine = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllEntitiesFilter, "Pick a line")

If (Not oLine Is Nothing) Then

    ' Set a reference to the drawing curve segment.
    ' This assumes that a drwaing curve is selected.
    Dim oDrawingCurveSegment As DrawingCurveSegment
    Set oDrawingCurveSegment = oLine
    
    ' Set a reference to the drawing curve.
    Dim oDrawingCurve As DrawingCurve
    Set oDrawingCurve = oDrawingCurveSegment.Parent
    
    ' Get the mid point of the selected curve
    ' assuming that the selection curve is linear
    Dim oMidPoint As Point2d
    Set oMidPoint = oDrawingCurve.MidPoint
    
    ' Set a reference to the TransientGeometry object.
    Dim oTG As TransientGeometry
    Set oTG = ThisApplication.TransientGeometry
    
    Dim oLeaderPoints As ObjectCollection
    Set oLeaderPoints = ThisApplication.TransientObjects.CreateObjectCollection
    
    ' Create a few leader points.
    Call oLeaderPoints.Add(oTG.CreatePoint2d(oMidPoint.x, oMidPoint.y))
    
    ' Create an intent and add to the leader points collection.
    ' This is the geometry that the symbol will attach to.
    Dim oGeometryIntent As GeometryIntent
    Set oGeometryIntent = oActiveSheet.CreateGeometryIntent(oDrawingCurve)
    
    Call oLeaderPoints.Add(oGeometryIntent)
    
    ' Get the first symbol definition
    Dim oSketchSymDef As SketchedSymbolDefinition
    Set oSketchSymDef = oDrawDoc.SketchedSymbolDefinitions.Item(name)
    
    ' Create the symbol with a leader
    Dim oSketchedSymbol As SketchedSymbol
    Set oSketchedSymbol = oActiveSheet.SketchedSymbols.AddWithLeader(oSketchSymDef, oLeaderPoints, rotary, , , False)
    
    GoTo Repeat

End If

End Sub

 

 

 

0 Likes