iLogic error creating linear dimension in 2D dwg

iLogic error creating linear dimension in 2D dwg

Daan_M
Collaborator Collaborator
513 Views
1 Reply
Message 1 of 2

iLogic error creating linear dimension in 2D dwg

Daan_M
Collaborator
Collaborator

Good morning,

 

My other post got a bit lengthy, managed to isolate the problem, haven't found a solution yet.

See the added files, im wondering wether it works for other people

When running the rule in the dwg, i get the following error: 

 

Daan_M_2-1597046651171.png

 

 

Code for reference:

 

'Drawing Document
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
If oDDoc Is Nothing Then MsgBox("No Active Drawing Document Found. Exiting.") : Return

'Model Document
If ThisDrawing.ModelDocument Is Nothing Then
	MsgBox("There is no model document associated with this drawing. Exiting.", vbOKOnly + vbExclamation, " ")
	Return
End If
Dim oMDocType As DocumentTypeEnum = ThisDrawing.ModelDocument.DocumentType
Dim oADoc As AssemblyDocument
Dim oADef As AssemblyComponentDefinition
If oMDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
	oADoc = ThisDrawing.ModelDocument
	oADef = oADoc.ComponentDefinition
Else
	MsgBox("The main model file being reference by this drawing is not an assembly." & vbCrLf & _
	"This rule only works when the model is an assembly document. Exiting.", vbOKOnly + vbExclamation, " ")
	Return
End If

Dim oSheet As Sheet = oDDoc.Sheets.Item(1)
Dim oView As DrawingView
For Each oDView As DrawingView In oSheet.DrawingViews
	If oDView.Name.Contains("VIEW2") Then
		oView = oDView
	End If
Next
If oView Is Nothing Then
	MsgBox("Couln't find a sheet with 'View2' in its name. Exiting.", vbOKOnly + vbExclamation, "VIEW NOT FOUND")
	Return
End If
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

Dim oWP1 As WorkPoint
Dim oWP2 As WorkPoint
Try
	oWP1 = oADef.WorkPoints.Item("PS1")
	oWP2 = oADef.WorkPoints.Item("PE1")
Catch oEx As Exception
	MsgBox("Couldn't find WorkPoints named 'PS1' & 'PE1'. Exiting.")
	Return
End Try

Dim oStyleMgr As DrawingStylesManager = oDDoc.StylesManager
Dim oCMStyle As CentermarkStyle
Try
	oCMStyle = oStyleMgr.CentermarkStyles.Item("Center Mark (ANSI)")
Catch oEx As Exception
	oProceed = MsgBox("Coundn't find a CentermarkStyle named 'Center Mark (ANSI)'." & vbCrLf & _
	"Do you want to proceed without specifying the Style?", vbYesNo + vbQuestion, "STYLE NOT FOUND")
	If oProceed = vbNo Then Return
End Try
Dim oCP1 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP1, oView, oCMStyle)
Dim oCP2 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP2, oView, oCMStyle)

Dim oInt1 As GeometryIntent = oSheet.CreateGeometryIntent(oCP1)
Dim oInt2 As GeometryIntent = oSheet.CreateGeometryIntent(oCP2)
Dim oPtText As Point2d
Dim oDimType As DimensionTypeEnum
Dim oHorV As String = "Horizontal" 'or "Vertical"
If oHorV = "Horizontal" Then
	oDimType = DimensionTypeEnum.kHorizontalDimensionType
	oPtText = oTG.CreatePoint2d(oView.Center.X,(oView.Top + 1))
Else
	oDimType = DimensionTypeEnum.kVerticalDimensionType
	oPtText = oTG.CreatePoint2d((oView.Left-1),oView.Center.Y)
End If
Dim oDim As DrawingDimension
Try
	oDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, oDimType)
Catch oEx As Exception
	MsgBox("The attempt to create the dimension failed." & vbCrLf & _
	"The Error message is as follows:" & vbCrLf & _
	oEx.Message & vbCrLf & vbCrLf & _
	"The Source is as follows:" & vbCrLf & _
	oEx.Source, vbOKOnly + vbExclamation, " ")
End Try

 

0 Likes
Accepted solutions (1)
514 Views
1 Reply
Reply (1)
Message 2 of 2

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Daan_M 

I dont have inventor 2021 so I cant test the code on your files.

I see however that your geometry intent variables are called oInt1 and oInt2, but in your line to add the dimension you use oGeomIntent1 and oGeomIntent2 that are not declared anywhere in the code.

 

It should probably look like this?

'Drawing Document
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule '" & iLogicVb.RuleName & "' only works for Drawing Documents.",vbOKOnly, "WRONG DOCUMENT TYPE")
	Return
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
If oDDoc Is Nothing Then MsgBox("No Active Drawing Document Found. Exiting.") : Return

'Model Document
If ThisDrawing.ModelDocument Is Nothing Then
	MsgBox("There is no model document associated with this drawing. Exiting.", vbOKOnly + vbExclamation, " ")
	Return
End If
Dim oMDocType As DocumentTypeEnum = ThisDrawing.ModelDocument.DocumentType
Dim oADoc As AssemblyDocument
Dim oADef As AssemblyComponentDefinition
If oMDocType = DocumentTypeEnum.kAssemblyDocumentObject Then
	oADoc = ThisDrawing.ModelDocument
	oADef = oADoc.ComponentDefinition
Else
	MsgBox("The main model file being reference by this drawing is not an assembly." & vbCrLf & _
	"This rule only works when the model is an assembly document. Exiting.", vbOKOnly + vbExclamation, " ")
	Return
End If

Dim oSheet As Sheet = oDDoc.Sheets.Item(1)
Dim oView As DrawingView
For Each oDView As DrawingView In oSheet.DrawingViews
	If oDView.Name.Contains("VIEW2") Then
		oView = oDView
	End If
Next
If oView Is Nothing Then
	MsgBox("Couln't find a sheet with 'View2' in its name. Exiting.", vbOKOnly + vbExclamation, "VIEW NOT FOUND")
	Return
End If
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry

Dim oWP1 As WorkPoint
Dim oWP2 As WorkPoint
Try
	oWP1 = oADef.WorkPoints.Item("PS1")
	oWP2 = oADef.WorkPoints.Item("PE1")
Catch oEx As Exception
	MsgBox("Couldn't find WorkPoints named 'PS1' & 'PE1'. Exiting.")
	Return
End Try

Dim oStyleMgr As DrawingStylesManager = oDDoc.StylesManager
Dim oCMStyle As CentermarkStyle
Try
	oCMStyle = oStyleMgr.CentermarkStyles.Item("Center Mark (ANSI)")
Catch oEx As Exception
	oProceed = MsgBox("Coundn't find a CentermarkStyle named 'Center Mark (ANSI)'." & vbCrLf & _
	"Do you want to proceed without specifying the Style?", vbYesNo + vbQuestion, "STYLE NOT FOUND")
	If oProceed = vbNo Then Return
End Try
Dim oCP1 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP1, oView, oCMStyle)
Dim oCP2 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP2, oView, oCMStyle)

Dim oInt1 As GeometryIntent = oSheet.CreateGeometryIntent(oCP1)
Dim oInt2 As GeometryIntent = oSheet.CreateGeometryIntent(oCP2)
Dim oPtText As Point2d
Dim oDimType As DimensionTypeEnum
Dim oHorV As String = "Horizontal" 'or "Vertical"
If oHorV = "Horizontal" Then
	oDimType = DimensionTypeEnum.kHorizontalDimensionType
	oPtText = oTG.CreatePoint2d(oView.Center.X,(oView.Top + 1))
Else
	oDimType = DimensionTypeEnum.kVerticalDimensionType
	oPtText = oTG.CreatePoint2d((oView.Left-1),oView.Center.Y)
End If
Dim oDim As DrawingDimension
Try
	oDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oInt1, oInt2, oDimType)
Catch oEx As Exception
	MsgBox("The attempt to create the dimension failed." & vbCrLf & _
	"The Error message is as follows:" & vbCrLf & _
	oEx.Message & vbCrLf & vbCrLf & _
	"The Source is as follows:" & vbCrLf & _
	oEx.Source, vbOKOnly + vbExclamation, " ")
End Try