AnsweredAssumed Answered

Drawing API Change all view configurations

Question asked by Michael Caulton on Jan 4, 2015
Latest reply on Jan 13, 2015 by Keith Rice

I am trying to write a VB.NET macro that changes all the views in a drawing sheet to match the selected configuration but can't get the drawing to behave predictably.

 

The idea is that there is a single "template" drawing file/sheet pre-setup for a part with multiple configurations. The user selects the desired configuration through the macro GUI and then the drawing updates so all views are correct. This removes the need to multiple sheets for each configuration and the drawings will look more uniform.

 

The drawing is setup so the biggest configuration is selected. This means when the configuration is changed there should be no overlap. Also during testing if one went from a smaller configuration to larger it would unpredictably move some dimensions.

 

if I run the code below to create a sketch point at each view position vPos(0),vPos(1), I get the "Image 1". The sketch point is the center point of each of the views.

 

        Dim swModel As IModelDoc2 = swApp.ActiveDoc

        Dim swDraw As SldWorks.DrawingDoc = swModel

        Dim swView As SldWorks.View

 

        Dim sConfig As String = "L1200"

 

        Dim vSheetProps As Object = swDraw.GetCurrentSheet.GetProperties

        Dim swDrawScale As Single = 1 / (vSheetProps(2) / vSheetProps(3))

 

        swView = swDraw.GetFirstView

        swView = swView.GetNextView

 

        Dim vPos As Object

 

        Do While Not swView Is Nothing

 

            ' Insert a point at vPos(0), vPos(1)

            vPos = swView.Position

            InsertPoint(swApp.ActiveDoc, vPos(0) * swDrawScale, vPos(1) * swDrawScale)

 

            swView = swView.GetNextView

 

        Loop

 

    Sub InsertPoint(swModel As SldWorks.ModelDoc2, x As Double, y As Double)

        Dim swSkMgr As SldWorks.SketchManager = swModel.SketchManager

        Dim skPoint As SldWorks.SketchPoint

        skPoint = swSkMgr.CreatePoint(x, y, 0.0#)

    End Sub

 

All the sketch points previously created are deleted and the revised code below is then run. The result "Image 2".

 

        Do While Not swView Is Nothing

 

            ' Change to new configuration

            If InStr(swView.ReferencedConfiguration, "SM-FLAT-PATTERN") > 0 Then

                swView.ReferencedConfiguration = sConfig + "SM-FLAT-PATTERN"

            Else : swView.ReferencedConfiguration = sConfig

            End If

 

            ' Insert a point at vPos(0), vPos(1)

            vPos = swView.Position

            InsertPoint(swApp.ActiveDoc, vPos(0) * swDrawScale, vPos(1) * swDrawScale)

 

            swView = swView.GetNextView

        Loop

 

The sketch point used to identify the position of the views is still in the same location and no longer in the center of the view.

 

How do I get the views to all stay centered about their middle during the configuration name change?

 

Attachments:

     Example part and drawing with single sheet

Outcomes