iLogic annotation placement

iLogic annotation placement

Daan_M
Collaborator Collaborator
2,124 Views
16 Replies
Message 1 of 17

iLogic annotation placement

Daan_M
Collaborator
Collaborator

Hi, 

 

I got the following code, it runs but it doesn't place a annotation,

I have adjusted quite a few things but can't figure out what i'm doing wrong, i think it's something small and is to be found in the first half of the code.....

 

more info: my sheetname in the dwg is 'MAIN' 

 

Public Sub WorkPoints
	
	Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oStyle As DrawingStylesManager = oDrawingDoc.StylesManager
	Dim oAssyDoc As AssemblyDocument = oDrawingDoc.AllReferencedDocuments.Item(1)
	Dim oAssyCompDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinitions.Item(1)
	Dim oCMStyle As CentermarkStyle = oStyle.CentermarkStyles.Item("Center Mark (ANSI)")
	
'*Define workpoint arrays
Dim sDimPt(2, 1) As String
		Dim Pt1 As Integer = 0

'*Define annotation start point
	sDimPt(0, Pt1) = "PS1"

'*Define annotation end points
	sDimPt(0, Pt2) = "PE1"

'*Define the views on which the annotation should be placed
	sDimPt(0, Pt3) = "View2"

'*Define sheet on which annotation should be placed
	sDimPt(0, Pt4) = "1"

'*Define annotation orientation
	sDimPt(0, Pt5) = "Horizontal"

'*Loop array to place
For j = 0 To 1
		sDimPt1 = sDimPt(j, Pt1)
		sDimPt2 = sDimPt(j, Pt2)
		viewName = sDimPt(j, Pt3)
		sheetIndex = CInt(sDimPt(j, Pt4))
		ActiveSheet = ThisDrawing.Sheet("MAIN:" & sheetIndex)

Dim oView As DrawingView = ActiveSheet.View(viewName).View
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(sheetIndex)
		CreateLinearDimension(oAssyCompDef, oView, oDrawingDoc, oSheet, sDimPt1, sDimPt2, oCMStyle, oDimType)
Next j
End Sub




'*iLogic automation annotation placement//////////////////////////////////////////////////////////////////////


Private Sub CreateLinearDimension(ByVal oAssyCompDef As AssemblyComponentDefinition, oView As DrawingView, oDrawingDoc As DrawingDocument, oSheet As Sheet, sDimPt1 As String, sDimPt2 As String, oCMStyle As CentermarkStyle, oDimType As String)
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry
	
	'---------Get Assembly Workpoints as Sheetpoints---------
	oWP1 = oAssyCompDef.WorkPoints.Item(sDimPt1)
	oWP2 = oAssyCompDef.WorkPoints.Item(sDimPt2)
	
	'---------Declare variables for Dimeensions endpoints and text location---------
	Dim oSheetPt1 As Point2d
	Dim oSheetPt2 As Point2d
	Dim oPtText As Point2d
	
	'---------Add Centermarks on the drawing attached to the assemblu workpoints for geometry intent---------
	Dim oCenterMark1 As Centermark
	Dim oCenterMark2 As Centermark

	'---------Create Geometry intent---------
	Dim oGeomIntent1 As GeometryIntent
	Dim oGeomIntent2 As GeometryIntent
	oGeomIntent1 = oSheet.CreateGeometryIntent(oCenterMark1, oSheetPoint1)
	oGeomIntent2 = oSheet.CreateGeometryIntent(oCenterMark2, oSheetPoint2)
	
	'---------Define Dimension Text Location---------
	Dim oPlaceDimX As Double
	Dim oPlaceDimY As Double
	
		If oDimType = "Vertical" Then
			oPlaceDimX = oSheetPt1.X 
			oPlaceDimY = oSheetPt1.Y
				dimTypeVal = 60163
			
			Else If oDimType = "Horizontal" Then
				oPlaceDimX = oSheetPt1.X
				oPlaceDimY = oSheetPt1.Y 
					dimTypeVal = 60162
				End If
				
	oPtText = oTG.CreatePoint2d(oPlaceDimX, oPlaceDimY0)
	
		'---------Create Dimension And center the text between the leaders---------
		Dim oDimension As DrawingDimension
			oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, dimTypeVal)
			
		End Sub

 

0 Likes
Accepted solutions (1)
2,125 Views
16 Replies
Replies (16)
Message 2 of 17

WCrihfield
Mentor
Mentor

I see where you defined the variable "Pt1" but I don't see where you've defined the variables "Pt2", "Pt3", "Pt4", or "Pt5", before trying to use them within the "sDimPt()" array of string, assignments.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 17

WCrihfield
Mentor
Mentor

Also I do you know that your line of code near the top "Dim sDimPt(2,1) As String" is creating a 2-dimensional array of strings that has 3 columns, and 2 rows?  When dealing with arrays, 0 is always counted as the first item in each dimension of it.  So there are 6 possible places to put a String within that array.  Unlike lists and collections, array's also have a set size, based on how you first call it out, so it's not easy (but not impossible) to add more items into it than its initial size allows.

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 4 of 17

Daan_M
Collaborator
Collaborator

Thank you, i wasn't fully aware how the multidimensional arrays worked.

I still don't get the dimension i want, but i corrected the code from what you pointed out below.

If anyone could help me solve this further that would be greatly appreciated.

 

 

Public Sub WorkPoints
	
	Dim oDrawingDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oStyle As DrawingStylesManager = oDrawingDoc.StylesManager
	Dim oAssyDoc As AssemblyDocument = oDrawingDoc.AllReferencedDocuments.Item(1)
	Dim oAssyCompDef As AssemblyComponentDefinition = oAssyDoc.ComponentDefinitions.Item(1)
	Dim oCMStyle As CentermarkStyle = oStyle.CentermarkStyles.Item("Center Mark (ANSI)")
	
'--------------------------------------------------

Dim sDimPt(2, 5) As String
		Dim Pt1 As Integer = 0
		Dim Pt2 As Integer = 1
		Dim Pt3 As Integer = 2
		Dim Pt4 As Integer = 3
		Dim Pt5 As Integer = 4

'*Define annotation start point
	sDimPt(0, Pt1) = "PS1"

'*Define annotation end points
	sDimPt(0, Pt2) = "PE1"

'*Define the views on which the annotation should be placed
	sDimPt(0, Pt3) = "View2"

'*Define sheet on which annotation should be placed
	sDimPt(0, Pt4) = "1"


'*Define annotation orientation
	sDimPt(0, Pt5) = "Horizontal"
	sDimPt(0, Pt5) = "Vertical"

'*Loop array 
For j = 0 To 1
		sDimPt1 = sDimPt(j, Pt1)
		sDimPt2 = sDimPt(j, Pt2)
		viewName = sDimPt(j, Pt3)
		sheetIndex = CInt(sDimPt(j, Pt4))
		ActiveSheet = ThisDrawing.Sheet("View2:" & sheetIndex)

Dim oView As DrawingView = ActiveSheet.View(viewName).View
Dim oSheet As Sheet = oDrawingDoc.Sheets.Item(sheetIndex)
		CreateLinearDimension(oAssyCompDef, oView, oDrawingDoc, oSheet, sDimPt1, sDimPt2, oCMStyle, oDimType)
Next j
End Sub



'annotation placement ---------------------------------

Private Sub CreateLinearDimension(ByVal oAssyCompDef As AssemblyComponentDefinition, oView As DrawingView, oDrawingDoc As DrawingDocument, oSheet As Sheet, sDimPt1 As String, sDimPt2 As String, oCMStyle As CentermarkStyle, oDimType As String)
	Dim oTG As TransientGeometry
	oTG = ThisApplication.TransientGeometry
	
	'---------Get Assembly Workpoints as Sheetpoints---------
	oWP1 = oAssyCompDef.WorkPoints.Item(sDimPt1)
	oWP2 = oAssyCompDef.WorkPoints.Item(sDimPt2)
	
	'---------Declare variables for Dimeensions endpoints and text location---------
	Dim oSheetPt1 As Point2d
	Dim oSheetPt2 As Point2d
	Dim oPtText As Point2d
	
	'---------Add Centermarks on the drawing attached to the assemblu workpoints for geometry intent---------
	Dim oCenterMark1 As Centermark
	Dim oCenterMark2 As Centermark

	'---------Create Geometry intent---------
	Dim oGeomIntent1 As GeometryIntent
	Dim oGeomIntent2 As GeometryIntent
	oGeomIntent1 = oSheet.CreateGeometryIntent(oCenterMark1, oSheetPoint1)
	oGeomIntent2 = oSheet.CreateGeometryIntent(oCenterMark2, oSheetPoint2)
	
	'---------Define Dimension Text Location---------
	Dim oPlaceDimX As Double
	Dim oPlaceDimY As Double
	
		If oDimType = "Vertical" Then
			oPlaceDimX = oSheetPt1.X - 2
			oPlaceDimY = oSheetPt1.Y
				dimTypeVal = 60163
			
			Else If oDimType = "Horizontal" Then
				oPlaceDimX = oSheetPt1.X
				oPlaceDimY = oSheetPt1.Y + 2
					dimTypeVal = 60162
				End If
				
	oPtText = oTG.CreatePoint2d(oPlaceDimX, oPlaceDimY0)
	
		'---------Create Dimension And center the text between the leaders---------
		Dim oDimension As DrawingDimension
			oDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, dimTypeVal)
			
		End Sub

 

 

 

My workpoints inside my assembly:

Daan_M_0-1596706905569.png

 

My sheet:

Daan_M_1-1596706948941.png

 

 

 

 

0 Likes
Message 5 of 17

WCrihfield
Mentor
Mentor

Try this.

If it works for you without errors, and creates the dimension,  then you we can figure out splitting it up into subs if you want.  It was just too complex and had too many variables without values the way it was.

I can't test it because I don't have the files.  If you run into some errors, we may have to put a lot more checks in there to make sure it is finding the values to the variables were trying to use, such as the drawing, assembly, sheet, view, work points, center mark styles, etc.

Sub Main 'Workpoints
	Dim oDDoc As DrawingDocument = ThisDrawing.Document
	Dim oStyleMgr As DrawingStylesManager = oDDoc.StylesManager
	Dim oADoc As AssemblyDocument = ThisDrawing.ModelDocument
	Dim oADef As AssemblyComponentDefinition = oADoc.ComponentDefinition
	Dim oCMStyle As CentermarkStyle = oStyleMgr.CentermarkStyles.Item("Center Mark (ANSI)")
	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
	Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
	Dim oWP1 As WorkPoint = oADef.WorkPoints.Item("PS1")
	Dim oWP2 As WorkPoint = oADef.WorkPoints.Item("PE1")
	Dim oCP1 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP1, oView)
	Dim oCP2 As Centermark = oSheet.Centermarks.AddByWorkFeature(oWP2, oView)
	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 = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, oDimType)
End Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 17

Daan_M
Collaborator
Collaborator

@WCrihfield i added your newly suggested code to the drawing template document, when i put the addembly model views in and run the code i get the following message;

 

Daan_M_0-1596788623032.png

 

I guess that means something is failing when trying to add the linear dimension? correct me if i'm wrong

 

0 Likes
Message 7 of 17

WCrihfield
Mentor
Mentor

Try this version now.

I've added a ton of checks and Try..Catch statements, that will hopefully give us more information about where something is going wrong for you.

'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
	

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 8 of 17

Daan_M
Collaborator
Collaborator

Hi @WCrihfield ,

 

I really appreciate your dedication in helping me out, your error checks isolate the problem to the position stated below, unfortunately it does not come up with a source.

 

if i comment the code below out, the rule runs smoothly.

 

'oDim = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, oDimType)

 

 

Daan_M_0-1596809937701.png

 

Might have to do something with the 2D point?

 

 

 

0 Likes
Message 9 of 17

tfrohe_LSI
Advocate
Advocate

Just a thought. I am not at my PC to test this but you are defining oDim as a DrawingDimension. While it is the parent class, you might find better success defining it as GeneralDimension instead since DrawingDimension does not have an AddLinear method.

 

Dim oDim As DrawingDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, oDimType)

 
so like this

Dim oDim As GeneralDimension = oSheet.DrawingDimensions.GeneralDimensions.AddLinear(oPtText, oGeomIntent1, oGeomIntent2, oDimType)

 

I'll try to test this out myself after the weekend. If you get a chance to test it before then, please post your findings.

Message 10 of 17

Daan_M
Collaborator
Collaborator

@tfrohe_LSI @WCrihfield , no succes yet, made a simple Part to test with, see added files. 

0 Likes
Message 11 of 17

Daan_M
Collaborator
Collaborator

@WCrihfield: Great solution.

@JhoelForshav noticed the following; "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 runs perfectly now, thanks alot!

0 Likes
Message 12 of 17

WCrihfield
Mentor
Mentor
Accepted solution

Wow, you're right. 😐 That's the kind of simple stuff you miss when you can't test the code before you post it.

So is this code working for you now?

'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, 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 GeneralDimension
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
	

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 13 of 17

Daan_M
Collaborator
Collaborator

@WCrihfield  Yes this works.

 

Small offtopic question, The code below works fine on my laptop, but on my desktop it fails...

 

 

Public Sub Main 

Dim KastVariant As String  = iPart.RowName("oTypeKast")
Dim MotorVariant as String = iPart.RowName("oTypeMotor")

End Sub

 

 

Error:

 

Daan_M_1-1597065551465.png

 

It seems like iLogic doesn't recognize the method, the text isnt purple and theres also no box that comes up to explain the arguments within it when i hoover my cursor over it, i haven't ran into this before

 

0 Likes
Message 14 of 17

WCrihfield
Mentor
Mentor

oTypeKast and oTypeMotor look like variable names.  If they are defined elsewhere within the main code block as a public or shared String?  If so, you can remove the quotation marks around them.

However, if they really are the direct names of components within your iPart table, they should work.

Do you have the Option "Straight VB code" turned on or off, within the iLogic Rule Editor dialog?

If it is off, and you're not planning on sharing this sub with another rule, you can get rid of the "Public" before Sub.

Public & Private are for when sharing the Sub/Function/etc. between multiple modules or rules.

Have you tried including a couple of MsgBox statements to check for the returned values?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 15 of 17

JhoelForshav
Mentor
Mentor

Hi @Daan_M 

Looking at your screenshot, I see no reason for the code to fail. Sometimes however, It can be more stable to use API calls instead of iLogic functionality. Maybe this works better?

Public Sub Main 
Dim oOccs As ComponentOccurrences = ThisDoc.Document.ComponentDefinition.Occurrences
Dim KastVariant As String  = oOccs.ItemByName("oTypeKast").Definition.iPartMember.Row.MemberName
Dim MotorVariant As String = oOccs.ItemByName("oTypeMotor").Definition.iPartMember.Row.MemberName
End Sub
0 Likes
Message 16 of 17

WCrihfield
Mentor
Mentor

@Daan_M 

You also may need to include a check to see if the active document is has an iPart table to access.

This won't work from just any document, without either the active document or a specified document containing an iPart table to search in.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 17 of 17

Daan_M
Collaborator
Collaborator

@JhoelForshav @WCrihfield 

The code doesn't work, same message.

The strangest thing is that iPart.ChangeRow works fine (the code below is from another rule, i added 'iPart.RowName' to it for testing); 

 

oTypeKast = GoExcel.CellValue(oExcelDoc, oSheet, "A1") 'import membername from Excel

iPart.ChangeRow("oTypeKast", oTypeKast) 'works fine
rowName = iPart.RowName("oTypeKast") 'doesnt work

 

I guess this means iLogic does have acces to the table since it can change rows.

 

I can find a way around the error  and link the Excel in my other rule aswell, and import it that way, like i did in the code above. I'm just curious to the cause of the error to help my understanding...

 

0 Likes