Help to insert SketchSymbol from Library/Template

Help to insert SketchSymbol from Library/Template

ngdnam88
Advocate Advocate
201 Views
2 Replies
Message 1 of 3

Help to insert SketchSymbol from Library/Template

ngdnam88
Advocate
Advocate

Dears,

I'm using this code to insert a sketch symbol from Library/Template file to working drawing. Please help me to check and give me another solution?

Dim oDOC As Inventor.DrawingDocument = _InventorApp.ActiveDocument
Dim oSSDefs As SketchedSymbolDefinitions = oDOC.SketchedSymbolDefinitions
Dim oLibrary As SketchedSymbolDefinitionLibrary = oSSDefs.SketchedSymbolDefinitionLibraries.Item("SketchSymbols.idw")
Dim wSSDef As SketchedSymbolDefinition = Nothing

Try
	wSSDef = oDOC.SketchedSymbolDefinitions.Item("ABC")
Catch ex As Exception
	wSSDef = oSSDefs.AddFromLibrary(oLibrary, "ABC", True)
End Try

For Each ChkObject As Object In oDOC.SelectSet
	If ChkObject.Type() = ObjectTypeEnum.kLinearGeneralDimensionObject Then
		Dim wPoint As Inventor.Point2d = ChkObject.DimensionLine.MidPoint
		Dim wSketchSymbol As SketchedSymbol = oDOC.ActiveSheet.SketchedSymbols.Add(wSSDef, wPoint, 0, 1, Nothing)
		wSketchSymbol.Static() = True
	End If
Next

My issue is: If SketchSymbol existed, it'll be insert corrected at the first time. If SketchSymbol doesn't existed, the SketchSymbol 'll copy to current drawing only and doesn't used at the first time - It'll insert at the second time when code run again!
I don't know why. Could you please help me. Thanks!

0 Likes
Accepted solutions (1)
202 Views
2 Replies
Replies (2)
Message 2 of 3

JelteDeJong
Mentor
Mentor
Accepted solution

The problem here is that you use the selection set. the selection set is cleared when you add a SketchedSymbol to you drawing.

To prevent this you could first look at your selection set and add all dimensions to a new list. Then get/add the sketched symbol. And then you only need to loop over the new list of dimensions. Something like this would work.

Dim oDOC As Inventor.DrawingDocument = ThisApplication.ActiveDocument
Dim oSSDefs As SketchedSymbolDefinitions = oDOC.SketchedSymbolDefinitions
Dim oLibrary As SketchedSymbolDefinitionLibrary = oSSDefs.SketchedSymbolDefinitionLibraries.Item("SketchSymbols.idw")
Dim wSSDef As SketchedSymbolDefinition = Nothing

' create and fill a list of LinearGeneralDimension
Dim dimensons As New List(Of LinearGeneralDimension)
For Each ChkObject As Object In oDOC.SelectSet
    If ChkObject.Type() = ObjectTypeEnum.kLinearGeneralDimensionObject Then
        dimensons.Add(ChkObject)
    End If
Next

Try
    wSSDef = oDOC.SketchedSymbolDefinitions.Item("ABC")
Catch ex As Exception
    wSSDef = oSSDefs.AddFromLibrary(oLibrary, "ABC", True)
End Try

' loop over the list of LinearGeneralDimension
For Each dimenson As LinearGeneralDimension In dimensons
    Dim wPoint As Inventor.Point2d = dimenson.DimensionLine.MidPoint
    Dim wSketchSymbol As SketchedSymbol = oDOC.ActiveSheet.SketchedSymbols.Add(wSSDef, wPoint, 0, 1, Nothing)
    wSketchSymbol.Static() = True
Next

 

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

Message 3 of 3

ngdnam88
Advocate
Advocate

Thanks @JelteDeJong 
I got it. It's working now!

0 Likes