Problem creating dimensions in a drawing from workpoints from parts with more than one model state

Problem creating dimensions in a drawing from workpoints from parts with more than one model state

gs104
Explorer Explorer
191 Views
1 Reply
Message 1 of 2

Problem creating dimensions in a drawing from workpoints from parts with more than one model state

gs104
Explorer
Explorer

I have a segment of working code ( an ilogic rule) that creates a drawing from a standard part and includes a vertical dimension between the centermarks of two workpoints. The workpoints exist on the part model, and this code uses them to create a dimension.

 

The problem is, when I add a second model state to the part, the dimension doesn't show up on the drawing anymore, even if the second model state isn't active and isn't really referenced in the code by anything I can find. Just by existing, the second model state seems to stop the dimension from being on the drawing. I think the problem starts around these two lines because I was running some try catch debugging and it was where things started going bad:

 

osectionview.SetIncludeStatus(oWP1, True) 'Includes the first workpoint in the drawing view' osectionview.SetIncludeStatus(oWP2, True) 'Includes the second workpoint in the drawing view'

 

Here is the code currently. Again it works perfectly with just a [Primary] model state, but when I make another model state, I get no dimension.

Dim oDoc As Document = ThisDoc.Document  'Identifies the active document as this document

'Dim oSep As Double = 2 ' Defines the separation between the views

'Create a drawing from the selected drawing template
Dim oFileDlg As Inventor.FileDialog = Nothing 'Creates a file selection dialog box'
ThisApplication.CreateFileDialog(oFileDlg)
oFileDlg.Filter = "Inventor Files (*.dwg)|*.dwg" 'Filters available files in the box for only dwg files' 'could also try idw files'
oFileDlg.DialogTitle = "Select Drawing Template" 'Names the top left corner of the box'
oFileDlg.InitialDirectory = ThisApplication.FileOptions.TemplatesPath
oFileDlg.CancelError = True 'Ends everything if you cancel out of the dialog box or don't select anything, without an error'
On Error Resume Next
oFileDlg.ShowOpen()
If Err.Number <> 0 Then
	Exit Sub
ElseIf oFileDlg.FileName <> "" Then
MasterFile = oFileDlg.FileName 'Assigns the masterfile as the selected file in the dialog box'
End If

Dim oDrawingDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, MasterFile, True)

oDrawingDoc.Activate() 'Activates the Drawing'
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(1) 'Creates a sheet'
oSheet.Activate

'Add an If loop here that makes oscale a function of size
Dim oScale As Double = 1 'Sets the scale for the drawing that use this variable'
'Add an If loop here that makes oBaseCenterPoint a function of  size and oscale
Dim oBaseCenterPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width/5, oSheet.Height/1.5) 'Defines a centerpoint in the upper left part of the sheet, will change to be a function of scale and venturi size'

Dim oView As DrawingView
oView = oSheet.DrawingViews.AddBaseView(oDoc,oBaseCenterPoint, oScale, ViewOrientationTypeEnum.kLeftViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle) 'Creates a bottom view of the drawing at the defined centerpoint'

Dim oSep As Double = 2 ' Defines the separation between the views. Is this needed?

'Put an if loop here that makes a double that is the x and y cooridinates of where the section drawing should be as a function of the size and scale of the venturi'
Dim SectionSketchBP As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X + 55, oView.Center.Y) 'Creates a point for the third view at x+55'

'Create Section View at center
Dim oSectionSketch As DrawingSketch 'Creates Section Line Sketch'
oSectionSketch = oView.Sketches.Add 'Adds a sketch to the base view'
oSectionSketch.Edit() 'Opens the sketch editor for the newly created sketch'
Dim oSectionLine As SketchLine 'Creates a line in the sketch'
oSpoint1 = ThisApplication.TransientGeometry.CreatePoint2d(0, 2.54*-FD/2-1) 'Creates a point at the bottom of the part from the base point of the sketch'
oSpoint2 = ThisApplication.TransientGeometry.CreatePoint2d(0, 2.54*FD/2+1) 'Creates a point at top of the part from the base point of the sketch'
oSectionLine = oSectionSketch.SketchLines.AddByTwoPoints(oSpoint1, oSpoint2) 'Creates a line by connecting the two points'
oSectionSketch.ExitEdit() 'Exits the sketch editor'
Dim osectionview As SectionDrawingView 'Creates a section view'
osectionview = oSheet.DrawingViews.AddSectionView(oView, oSectionSketch, SectionSketchBP, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, oScale, True, "A")

'Put an if loop here that makes a double that is the x and y cooridinates of where the section drawing should be as a function of the size and scale of the venturi'
Dim SectionSketch2BP As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oView.Center.X + 20, oView.Center.Y) 'Creates a point for the second view at x+20'

Dim oGeomIntent1 As Inventor.GeometryIntent
Dim oGeomIntent2 As Inventor.GeometryIntent

Dim oWP1 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("InletODTop") 'Creates a workpoint from the workpoint in the model called Work Point1'
Dim oWP2 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("InletODBtm") 'Creates a workpoint from the workpoint in the model called Work Point4'
        
osectionview.SetIncludeStatus(oWP1, True) 'Includes the first workpoint in the drawing view'
osectionview.SetIncludeStatus(oWP2, True) 'Includes the second workpoint in the drawing view'

Dim oCenterMark1 As Inventor.Centermark
Dim oCenterMark2 As Inventor.Centermark
Dim oCenterMark As Inventor.Centermark

For Each oCenterMark In oSheet.Centermarks

            If oCenterMark.Attached Then
                If oCenterMark.AttachedEntity Is oWP1 Then               
                    oCenterMark1 = oCenterMark
                End If
                If oCenterMark.AttachedEntity Is oWP2 Then
                    oCenterMark2 = oCenterMark                    
                End If
            End If
        Next
       
oGeomIntent1 = oSheet.CreateGeometryIntent(oCenterMark1, kPoint2dIntent)
oGeomIntent2 = oSheet.CreateGeometryIntent(oCenterMark2, kPoint2dIntent)
        
oCenterMark1.Visible = False 'Makes the centermark for the first workpoint invisible'
oCenterMark2.Visible = False 'Makes the centermark for the second workpoint invisible'

Dim textPoint As Inventor.Point2d = ThisServer.TransientGeometry.CreatePoint2d(SectionSketchBP.X - 15, SectionSketchBP.Y) 'Creates a text point @ the base drawing centerpoint+15 for x and the same Y as the base point of the base drawing'
Dim oDim As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(textPoint, oGeomIntent1, oGeomIntent2, DimensionTypeEnum.kVerticalDimensionType) 'Draws a vertical linear dimension from the 2 centermarks and places the number at the test point'

 

0 Likes
192 Views
1 Reply
Reply (1)
Message 2 of 2

grantDHM4Z
Participant
Participant

I made a simpler model and a simpler code to show the problem to anyone wants to take a look. The two files attached are identical except one has a model state other than [Primary]. If you run the "DWG Create Latest" Rule in each file, you will see that one creates a drawing with dimensions and one doesn't, and I can't figure out why.

0 Likes