Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Sample Code does not work

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
pnut71790
519 Views, 2 Replies

Sample Code does not work

The Sample code from the 2013 Inventor help for Creating sketched symbol definitions doesn't want to work.

 

 

   

Friend ThisApplication As Inventor.Application

   

PublicSub CreateSketchedSymbolDefinition()

       

' Set a reference to the drawing document.

       

' This assumes a drawing document is active.

       

Dim oDrawDoc AsDrawingDocument = ThisApplication.ActiveDocument

       

' Create the new sketched symbol definition.

       

Dim oSketchedSymbolDef AsSketchedSymbolDefinition

        oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Add(

"Circular Callout")

       

' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit

       

' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates

       

' a copy of the sketched symbol definition's and opens it for edit.

       

Dim oSketch AsDrawingSketch

       

Call oSketchedSymbolDef.Edit(oSketch)

       

Dim oTG AsTransientGeometry

        oTG = ThisApplication.TransientGeometry

       

' Use the functionality of the sketch to add sketched symbol graphics.

       

Dim oSketchLine AsSketchLine

        oSketchLine = oSketch.SketchLines.AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(20, 0))

       

Dim oSketchCircle AsSketchCircle

        oSketchCircle = oSketch.SketchCircles.AddByCenterRadius(oTG.CreatePoint2d(22, 0), 2)

       

Call oSketch.GeometricConstraints.AddCoincident(oSketchLine.EndSketchPoint, oSketchCircle)

       

' Make the starting point of the sketch line the insertion point

        oSketchLine.StartSketchPoint.InsertionPoint =

True

       

' Add a prompted text field at the center of the sketch circle.

       

Dim sText AsString

        sText =

"\</Prompt\>Enter text 1\</Prompt\>"

       

Dim oTextBox AsTextBox

        oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22, 0), sText)

        oTextBox.VerticalJustification =

VerticalTextAlignmentEnum.kAlignTextMiddle

        oTextBox.HorizontalJustification =

HorizontalTextAlignmentEnum.kAlignTextCenter

       

Call oSketchedSymbolDef.ExitEdit(True)

   

EndSub

   

PublicSub InsertSketchedSymbolOnSheet()

       

       

' Set a reference to the drawing document.

       

' This assumes a drawing document is active.

       

Dim oDrawDoc AsDrawingDocument

        oDrawDoc = ThisApplication.ActiveDocument

       

' Obtain a reference to the desired sketched symbol definition.

       

Dim oSketchedSymbolDef AsSketchedSymbolDefinition

        oSketchedSymbolDef = oDrawDoc.SketchedSymbolDefinitions.Item(

"Circular Callout")

       

Dim oSheet AsSheet

        oSheet = oDrawDoc.ActiveSheet

       

' 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) AsString

        sPromptStrings(0) =

"A"

       

Dim oTG AsTransientGeometry

        oTG = ThisApplication.TransientGeometry

       

' 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 AsSketchedSymbol

        oSketchedSymbol = oSheet.SketchedSymbols.Add(oSketchedSymbolDef, oTG.CreatePoint2d(0, 0), (3.14159 / 4), 0.75, sPromptStrings)

   

EndSub

 

 

2 REPLIES 2
Message 2 of 3

This code works fine for me.  Pay attention to prompted text format.

 

    Public Sub CreateSketchedSymbolDefinition()

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

        ' Create the new sketched symbol definition.
        Dim oSketchedSymbolDef As SketchedSymbolDefinition _
            = oDrawDoc.SketchedSymbolDefinitions.Add("Circular Callout")

        ' Open the sketched symbol definition's sketch for edit. This is done by calling the Edit
        ' method of the SketchedSymbolDefinition to obtain a DrawingSketch. This actually creates
        ' a copy of the sketched symbol definition's and opens it for edit.
        Dim oSketch As DrawingSketch = Nothing
        Call oSketchedSymbolDef.Edit(oSketch)

        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

        ' Use the functionality of the sketch to add sketched symbol graphics.
        Dim oSketchLine As SketchLine = oSketch.SketchLines _
            .AddByTwoPoints(oTG.CreatePoint2d(0, 0), oTG.CreatePoint2d(20, 0))

        Dim oSketchCircle As SketchCircle = oSketch.SketchCircles _
            .AddByCenterRadius(oTG.CreatePoint2d(22, 0), 2)

        Call oSketch.GeometricConstraints.AddCoincident( _
                oSketchLine.EndSketchPoint, oSketchCircle)

        ' Make the starting point of the sketch line the insertion point
        oSketchLine.StartSketchPoint.InsertionPoint = True

        ' Add a prompted text field at the center of the sketch circle.
        Dim sText As String = "<Prompt>Enter text 1</Prompt>"

        Dim oTextBox As Inventor.TextBox
        oTextBox = oSketch.TextBoxes.AddFitted(oTG.CreatePoint2d(22, 0), sText)
        oTextBox.VerticalJustification = VerticalTextAlignmentEnum.kAlignTextMiddle
        oTextBox.HorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter

        Call oSketchedSymbolDef.ExitEdit(True)

    End Sub


    Public Sub InsertSketchedSymbolOnSheet()

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

        ' Obtain a reference to the desired sketched symbol definition.
        Dim oSketchedSymbolDef As SketchedSymbolDefinition _
            = oDrawDoc.SketchedSymbolDefinitions.Item("Circular Callout")

        Dim oSheet As Sheet = oDrawDoc.ActiveSheet

        ' 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) = "AAAAA"

        Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

        ' 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 = oSheet.SketchedSymbols.Add( _
                oSketchedSymbolDef, _
                oTG.CreatePoint2d(0, 0), _
                (3.14159 / 4), _
                0.75, _
                sPromptStrings)
    End Sub

 The sample VB .NET project is attached.


Vladimir Ananyev
Developer Technical Services
Autodesk Developer Network

Message 3 of 3
pnut71790
in reply to: pnut71790

Thanks that really seemed to help.

 

Thanks,

Matthew

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report