Ilogic rule to retrieve parameters and bypass if not exist.

Ilogic rule to retrieve parameters and bypass if not exist.

Anonymous
Not applicable
2,800 Views
10 Replies
Message 1 of 11

Ilogic rule to retrieve parameters and bypass if not exist.

Anonymous
Not applicable

I wrote a rule to retrieve values from parameters, but if the parameters doesn't not exist from the model. The program complain and won't run. How can I bypass if the parameters does't not exist.

Following is the code:

 

SyntaxEditor Code Snippet

'Extract Information from the part to a text file
 'My.Computer.FileSystem.WriteAllText("C:\TestFolder1\test.txt", Title + vbNewLine + Mfg + vbNewLine+ Mfg_no+ vbNewLine + SuggestedVendor +vbNewLine + SuggestedVendorPartNumber + vbNewLine + DST_Cost ,True
 'part_Number = iProperties.Value("Project", "Part Number")
 Dim part_Number As String
 Dim part_Revision As String
 Dim sFileName As String
 Dim tabs As String = "ITEM    QTY    PART_NO    DESCRIPTION    REFERENCE"
 Dim sp As String = "            "
 Dim fFile As IO.File
 Dim pTitle As String
 Dim pMfg As String
 Dim pMfg_no As String
 Dim pSuggestedVendor As String
 Dim pSuggestedVendorPartNumber As String
 Dim pDST_Cost As String
 
 part_Number = ThisDoc.FileName
 part_Revision = iProperties.Value("Project", "Revision Number")

 If iProperties.Value("Custom", "Title") = Isempty Then
     pTitle = Isempty
 
 Else
    pTitle = iProperties.Value("Custom", "Title")
 End If
 
 If (iProperties.Value("Custom", "Mfg")) = Isempty Then
     pMfg = Isempty
 Else
     pMfg = iProperties.Value("Custom", "Mfg")
 End If
 
 If (iProperties.Value("Custom", "Mfg_no")) = Isempty Then
      pMfg_no = Isempty
 Else
     pMfg_no = iProperties.Value("Custom", "Mfg_no")

 End If
 
If (iProperties.Value("Custom", "SuggestedVendor")) = Isempty Then
     pSuggestedVendor = Isempty

Else
    pSuggestedVendor = iProperties.Value("Custom", "SuggestedVendor")
End If

If (iProperties.Value("Custom", "SuggestedVendorPartNumber")) = Isempty Then
     pSuggestedVendorPartNumber = Isempty
Else
    pSuggestedVendorPartNumber = iProperties.Value("Custom", "SuggestedVendorPartNumber")
End If 


If (iProperties.Value("Custom", "DST_Cost")) = Isempty Then
     pDST_Cost = Isempty
Else
    pDST_Cost = iProperties.Value("Custom", "DST_Cost")
End If 
 
  My.Computer.FileSystem.WriteAllText("C:\TestFolder1\"+part_Number+"_R0"+part_Revision+".txt", tabs +vbNewLine +"1"+sp+ pTitle + vbNewLine +"2"+sp+ pMfg + vbNewLine +"3"+sp+pMfg_no+vbNewLine+"4"+sp+ iProperties.Value("Custom", "SuggestedVendor") +vbNewLine +"5"+sp+iProperties.Value("Custom", "SuggestedVendorPartNumber") + vbNewLine +"6"+sp+ iProperties.Value("Custom", "DST_Cost") ,True, System.Text.Encoding.ASCII)
 
 iLogicVb.UpdateWhenDone = True
 
 
 RuleFail.jpg
0 Likes
Accepted solutions (1)
2,801 Views
10 Replies
Replies (10)
Message 2 of 11

Xun.Zhang
Alumni
Alumni

@YuhanZhang, Any best practice to ignore empty property?

Thanks!


Xun
0 Likes
Message 3 of 11

bradeneuropeArthur
Mentor
Mentor
If (iProperties.Value("Custom", "SuggestedVendorPartNumber")) = Isempty Then
     pSuggestedVendorPartNumber = Isempty
resume next Else

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 4 of 11

bradeneuropeArthur
Mentor
Mentor

Do this:

 

try 
iProperties.Value("Custom", "SuggestedVendor")
If (iProperties.Value("Custom", "SuggestedVendor")) = Isempty Then
     pSuggestedVendor = Isempty

Else
    pSuggestedVendor = iProperties.Value("Custom", "SuggestedVendor")
End If

catch

end try

This is how you first check if the property exist in the file. 

 

Regards,

Regards,

Autodesk Software: Inventor Professional 2018 | Vault Professional 2018 | Autocad Mechanical 2018
Programming Skills: Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Dimension Component! | Partlist Export! | Derive I-properties! | Vault Prompts Via API! | Vault Handbook/Manual!
Drawing Toggle Sheets! | Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 5 of 11

Anonymous
Not applicable

I changed the code per your suggestion but I am getting different errors.

 

SyntaxEditor Code Snippet

Try
    iProperties.Value("Custom", "SuggestedVendor")
    If(iProperties.Value("Custom", "SuggestedVendor")) = Isempty Then
        pSuggestedVendor = Isempty
    Else
        pSuggestedVendor = iProperties.Value("Custom", "SuggestedVendor")
    End If
    
Catch
    
End Try


the ERROR is
Error on line 50: Property access must assign to the property or use its value.

Line 50:
iProperties.Value("Custom", "SuggestedVendor")

RuleFail2.jpg
0 Likes
Message 6 of 11

YuhanZhang
Autodesk
Autodesk
Accepted solution

Here is a sample iLogic code to check if a custom property is already defined:

 

On Error Resume Next
Dim pSuggestedVendor 
pSuggestedVendor = iProperties.Value("Custom", "SuggestedVendor")

If Err.Number <> 0 Then
	pSuggestedVendor = Isempty
	Err.Clear 
End If

On Error GoTo 0

 

 

Hope it helps.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 7 of 11

Anonymous
Not applicable

Yuhan Zhang,

 

That code work perfectly ,  it does everything  I need to extract custom iProperties from my part.ipt. But when I tried to extract custom iProperties from my drawing.idw, there are some issues:

1) My model custom iProperties are not transfer to my drawing.idw, therefore some of custom iProperties are blank.

2) I manually link my drawing with my model:

Tools -> Document Setting -> Drawing Tabs -> Copy Model iProperty Settings -> select All Properties

 

Is there any iLogic rules or macro that I can write to do the task to be able to update iProperties from model to drawing.

0 Likes
Message 8 of 11

YuhanZhang
Autodesk
Autodesk

You can copy the model custom properties to the drawing document using iLogic, below is a sample iLogic code, you can run it in a drawing document:

 

Sub Main()
	' get the first model document referenced by the drawing document.
	Dim oModelDoc As Document
	oModelDoc = ThisDrawing.ModelDocument 'oBase.ReferencedDocumentDescriptor.ReferencedDocument
	
	Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisDrawing.Document 
	
	' copy all the custom properties from the model document to drawing document.
	Dim oCustomProp As Inventor.Property
	Dim oProp As Inventor.Property
	
	On Error Resume Next
	For Each oCustomProp In oModelDoc.PropertySets(4)
		' check if the drawing document already has a custom property from model document
		oProp = oDrawDoc.PropertySets(4).Item(oCustomProp.Name)
		
		If Err.Number <> 0 Then
			Err.Clear 
			oProp = oDrawDoc.PropertySets(4).Add(oCustomProp.Value, oCustomProp.Name)
		Else
			oProp.Value = oCustomProp.Value
		End If
		
		oProp = Nothing
	Next

	On Error GoTo 0
	
End Sub

 

 

Please let me if more questions.



If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 9 of 11

RoyWickrama_RWEI
Advisor
Advisor

Nice coding. I like it.

With an iLogic rule running in a drawing document, I am interested retrieving the custom properties of a document (part or assembly) which is different from the drawing-model-document. Path and file name of this non-drawing-model-document is known.

 

I tried with my ability, but no success yet. I appreciate if you could you help me or provide with some hint to get this around.

 

0 Likes
Message 10 of 11

YuhanZhang
Autodesk
Autodesk

Try below iLogic code, change the sPath to your model's full filename:

 

Sub Main()
	' get the model document.
	Dim sPath As String
	sPath = "C:\Temp\MyModel.ipt"

Dim oModelDoc As Document
oModelDoc = ThisApplication.Documents.Open(sPath, False)
	
	Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisDrawing.Document 
	
	' copy all the custom properties from the model document to drawing document.
	Dim oCustomProp As Inventor.Property
	Dim oProp As Inventor.Property
	
	On Error Resume Next
	For Each oCustomProp In oModelDoc.PropertySets(4)
		' check if the drawing document already has a custom property from model document
		oProp = oDrawDoc.PropertySets(4).Item(oCustomProp.Name)
		
		If Err.Number <> 0 Then
			Err.Clear 
			oProp = oDrawDoc.PropertySets(4).Add(oCustomProp.Value, oCustomProp.Name)
		Else
			oProp.Value = oCustomProp.Value
		End If
		
		oProp = Nothing
	Next

	On Error GoTo 0
	
End Sub


If this solves the problem please click ACCEPT SOLUTION so other people can find it easily.



Rocky Zhang
Inventor API PD
Manufacturing Solutions
Autodesk, Inc.

Message 11 of 11

RoyWickrama_RWEI
Advisor
Advisor

Hi YuhanZhang;

It is a great help. It works fine 100%. Also, it helped me to around my current need (that I tested with the sample code shown below):

 

Sub Main()
	' get the model document.
	Dim sPath As String
	sPath = "C:\$WF_DHAMAG\Projects\DHAMAG_SDAI\ADSI-P001-ARF33\P001-A0001.iam"

oCustomProp_X = "TOTAL QTY"
Dim oModelDoc As Document
oModelDoc = ThisApplication.Documents.Open(sPath, False)
	
	Dim oDrawDoc As DrawingDocument
	oDrawDoc = ThisDrawing.Document 
	
	' copy all the custom properties from the model document to drawing document.
	Dim oCustomProp As Inventor.Property
	Dim oProp As Inventor.Property
	
	On Error Resume Next
	oPropsSet = oModelDoc.PropertySets.Item("Inventor User Defined Properties")
	For Each oCustomProp In oPropsSet		'oModelDoc.PropertySets(4)
			If oCustomProp.Name = oCustomProp_X Then
			MessageBox.Show("oCustomProp.Name: " & oCustomProp.Name _
			& vbLf & "oCustomProp.Value: " & oCustomProp.Value, "Title")	
			End If
	Next oCustomProp
	
	oTest = iProperties.Value(oModelDoc, "Custom", oCustomProp_X)
	If Err.Number <> 0 Then
	MessageBox.Show("@ Err!", "Title")
		Err.Clear 
		oProp = oPropsSet.Add("", oCustomProp_X)
		MessageBox.Show("Created!", "Title")
	End If
End Sub

Thanks a lot.

 

The idea of the oModelDoc using sPath is great.

0 Likes