Attach sketch symbol to the line sketch in drawing view using inventor API

Attach sketch symbol to the line sketch in drawing view using inventor API

thanh.trantuan
Contributor Contributor
1,156 Views
7 Replies
Message 1 of 8

Attach sketch symbol to the line sketch in drawing view using inventor API

thanh.trantuan
Contributor
Contributor

Hi everyone, 

I want to attach sketch symbols to the exist sketch on the chosen view by using VBA

Step 1: Create 1 sketch that include small lines. These lines are equal and horizontal constraint of each other. Each line is collinear constraint on the part’s edge

1.png

when using the collinear constraint between the line sketch and the part's edge, this edge is at the base workplane where located part's profile

1.png

Step 2: Attach sketch symbols (named FRTA and FRTB) to these line sketches made at the step 1

1.png

Note that FRTA is used for part which through its thickness from the right hand side to the left hand side

FRTB is used for part which through its thickness from the left hand side to the right hand side

I also attached model and drawing here for further investigate

Many thanks

0 Likes
1,157 Views
7 Replies
Replies (7)
Message 2 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@thanh.trantuan,

 

For inserting symbol into view , try below VBA code. Selecting either FRTB or FRTA symbol is depends on your logic.

Sub Insert_Symbol()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oView As DrawingView
    Set oView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a View")
    
    If oView Is Nothing Then
        Exit Sub
    End If
    
    Dim oSketch As DrawingSketch
    Dim oLine As SketchLine
     
    For Each oSketch In oView.Sketches
        If oSketch.SketchLines.count > 0 Then
            For Each oLine In oSketch.SketchLines
                
                Dim oPt As Point2d
                Set oPt = oView.DrawingViewToSheetSpace(oLine.StartSketchPoint.Geometry)
                
                Dim oSketchedSymbolDef As SketchedSymbolDefinition
                Set oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item("FRTB")
                ' This sketched symbol definition contains one prompted string input. An array
                ' must be input that contains the strings for the prompted strings.
                Dim sPromptStrings(0) As String
                sPromptStrings(0) = "T"
             
            
                ' Add an instance of the sketched symbol definition to the sheet.
                ' Rotate the instance by 45 degrees and scale by .75 when adding.
                ' The symbol will be inserted at (0,0) on the sheet. Since the
                ' start point of the line was marked as the insertion point, the
                ' start point should end up at (0,0).
                Dim oSketchedSymbol As SketchedSymbol
                Set oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPt, 0, 1, sPromptStrings)

            Next
        Else
            Resume Next
        End If
    Next
    
End Sub

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 3 of 8

thanh.trantuan
Contributor
Contributor

@chandra.shekar.g 

Thanks for your instruction

In this code, the sketch symbol will be inserted to all line sketches within the sketch of the active drawing view. So as you see, when I draw some small line to determine the position of the sketch symbol, I use Collinear constraint between these lines and the vertical projected line in the main structure. 

So the sketch symbol are inserted to the projected line also. (picture below)

1.JPG

Could you take a look again this code, sketch symbol just need to be inserted to small line sketch only (see picture below)

2.JPG

Many thanks

0 Likes
Message 4 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@thanh.trantuan,

 

As the length of line is consistent and measured as 4 cm, try below VBA code to insert on small line.

Sub Insert_Symbol()
    Dim oDoc As DrawingDocument
    Set oDoc = ThisApplication.ActiveDocument
    
    Dim oSheet As Sheet
    Set oSheet = oDoc.ActiveSheet
    
    Dim oView As DrawingView
    Set oView = ThisApplication.CommandManager.Pick(kDrawingViewFilter, "Select a View")
    
    If oView Is Nothing Then
        Exit Sub
    End If
    
    Dim oSketch As DrawingSketch
    Dim oLine As SketchLine
     
    For Each oSketch In oView.Sketches
        If oSketch.SketchLines.count > 0 Then
            For Each oLine In oSketch.SketchLines
                
                If oLine.Length = 4 Then
                    Dim oPt As Point2d
                    Set oPt = oView.DrawingViewToSheetSpace(oLine.StartSketchPoint.Geometry)
                    
                    Dim oSketchedSymbolDef As SketchedSymbolDefinition
                    Set oSketchedSymbolDef = oDoc.SketchedSymbolDefinitions.Item("FRTB")
                    ' This sketched symbol definition contains one prompted string input. An array
                    ' must be input that contains the strings for the prompted strings.
                    Dim sPromptStrings(0) As String
                    sPromptStrings(0) = "T"
                 
                
                    ' Add an instance of the sketched symbol definition to the sheet.
                    ' Rotate the instance by 45 degrees and scale by .75 when adding.
                    ' The symbol will be inserted at (0,0) on the sheet. Since the
                    ' start point of the line was marked as the insertion point, the
                    ' start point should end up at (0,0).
                    Dim oSketchedSymbol As SketchedSymbol
                    Set oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oPt, 0, 1, sPromptStrings)
                End If

            Next
        Else
            Resume Next
        End If
    Next
    
End Sub

In future drawing, make sure that line should drawn as 4 cm (40 mm) to insert symbol.

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



Message 5 of 8

thanh.trantuan
Contributor
Contributor

@chandra.shekar.g 

Do you know the reason why when I move the drawingview, these sketch symbols don't move too. They are just at their location. 

1.PNG

0 Likes
Message 6 of 8

thanh.trantuan
Contributor
Contributor

@chandra.shekar.g 

Could you take a look at this problem? This sketch symbols don't move with the view after dragging the position of this view. 

Thanks for your kind help

0 Likes
Message 7 of 8

chandra.shekar.g
Autodesk Support
Autodesk Support

@thanh.trantuan,

 

Hoping that suggestion in the below form link may be helpful.

 

https://forums.autodesk.com/t5/inventor-customization/how-to-attach-sketched-symbol-leader-to-view-i...

 

Thanks and regards,


CHANDRA SHEKAR G
Developer Advocate
Autodesk Developer Network



0 Likes
Message 8 of 8

thanh.trantuan
Contributor
Contributor

@chandra.shekar.g 

Many thanks

0 Likes