Change LineType on "Get Model Sketches" type curves

Change LineType on "Get Model Sketches" type curves

BromanSillito
Advocate Advocate
585 Views
2 Replies
Message 1 of 3

Change LineType on "Get Model Sketches" type curves

BromanSillito
Advocate
Advocate

I am using the api to create a drawing of an assembly which has a part in it that is only a sketch (kind of a semi-skeleton sketch). I am trying to show this sketch in the drawing and then change the linetype of the lines of the sketch. I have been able to show the sketch using the "SetVisibility" method, but I cannot find a good way to find the sketch curves to change their linetype. The only way I have found is by adding all the curves to an object collection initially and then after using SetVisibility to show the sketch I iterate through those curves again and change the linetype of any curves that are not in the object collection created previously.  This is very slow.  Can anybody out there tell me a faster way to find these curves? Here is some of the code I am using:

 

            
Dim elemSketch As PlanarSketch = wdDef.Sketches.Item(2)
Dim wdColl As ObjectCollection = oInventorApp.TransientObjects.CreateObjectCollection For Each dc As DrawingCurve In oMainView.DrawingCurves wdColl.Add(dc) Next oMainView.SetVisibility(elemSketch, True) For Each dc As DrawingCurve In oMainView.DrawingCurves For count = 1 To wdColl.Count If wdColl(count) Is dc Then GoTo A1 End If Next dc.LineType = LineTypeEnum.kDashedHiddenLineType dc.LineWeight = 0.1 A1: Next
0 Likes
Accepted solutions (2)
586 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

The DrawingCurves property has an optional input where you can specify the object you want to get the drawing curves for.  Using this you can pass in the sketch and then it will only return the drawing curves from the sketch.  Below is an example.

 

Public Sub GetSketchCurves()
    Dim drawDoc As DrawingDocument
    Set drawDoc = ThisApplication.ActiveDocument
    
    Dim drawView As DrawingView
    Set drawView = drawDoc.ActiveSheet.DrawingViews.Item(3)
    
    Dim partDoc As PartDocument
    Set partDoc = drawView.ReferencedDocumentDescriptor.ReferencedDocument
    
    Dim partDef As PartComponentDefinition
    Set partDef = partDoc.ComponentDefinition
    Dim sk As sketch
    Set sk = partDef.sketches.Item("Sketch2")
    
    Dim drawCurves As DrawingCurvesEnumerator
    Set drawCurves = drawView.DrawingCurves(sk)
    
    Dim drawCurve As DrawingCurve
    For Each drawCurve In drawCurves
        drawCurve.LineType = kDashedDoubleDottedLineType
    Next
End Sub

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

BromanSillito
Advocate
Advocate
Accepted solution

Thanks Brian!  That did the trick. The only modification I had to make was to create a PlanarSketchProxy and used that as the DrawingCurves input since the drawing was of an assembly and the sketch was on a component occurrence inside of the assembly. Here's the code I used for anybody interested:

 

Dim oAsmDoc As AssemblyDocument = oInventorApp.ActiveDocument
Dim oAsmDef As AssemblyComponentDefinition = oAsmDoc.ComponentDefinition

Dim wdPart As ComponentOccurrence = oAsmDef.Occurrences.Item(1)
Dim wdDef As PartComponentDefinition = wdPart.Definition

Dim elemSketch As PlanarSketch = wdDef.Sketches.Item(2)
Dim elemSketchProxy As PlanarSketchProxy = Nothing
wdPart.CreateGeometryProxy(elemSketch, elemSketchProxy)

Dim oMainView As DrawingView = CreateView(oAsmDoc, oMainPos, viewRight, viewVisible)

Dim drawCurves As DrawingCurvesEnumerator
drawCurves = oMainView.DrawingCurves(elemSketchProxy)

Dim drawCurve As DrawingCurve
For Each drawCurve In drawCurves
    drawCurve.LineType = LineTypeEnum.kDashedHiddenLineType
Next
0 Likes