iLogic Rule - Convert part type from above assembly

iLogic Rule - Convert part type from above assembly

garethsmithHMNMK
Contributor Contributor
884 Views
9 Replies
Message 1 of 10

iLogic Rule - Convert part type from above assembly

garethsmithHMNMK
Contributor
Contributor

Hi,

 

I'd like a part type (sheet metal vs standard part) to be driven from a parameter in the part. However, I want to be able to fire the rule from an assembly and not in the part. The below works fine if the rule is run within the part but when fired from an above assembly it errors.

 

I kind of know why but can't seem to find the answer.  Can anyone help please?

 

If SEAL_CUSTOM_EXTENTS = "REQUIRED" Then 
iProperties.Value("Project", "Part Number") = "N/A"
iProperties.Value("Summary", "Keywords") = "RTSM"
ThisApplication.ActiveDocument.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"
Else
iProperties.Value("Summary", "Keywords") = "N/A"
ThisApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
End If

 

0 Likes
Accepted solutions (1)
885 Views
9 Replies
Replies (9)
Message 2 of 10

WCrihfield
Mentor
Mentor

If this is the entire rule, then I assume it is a local iLogic rule and that "SEAL_CUSTOM_EXTENTS" is the name of a local Parameter.  If so, that Parameter would need to exist within the Assembly.

Or if that parameter only exists within the target part, you would have to access its similarly to this:

If Parameter.Value(oTargetDoc.DisplayName,"SEAL_CUSTOM_EXTENTS") = "REQUIRED" Then

for it to work.

When using the iProperties.Value() route to access the iProperties, and you are not specifying a component name or a document name as the first input variable, you are accessing the iProperties of the document which contains this rule.  To access the iProperties of the target part file, you would either need to specify that part documents name as the first input variable (similarly to how I am doing in the Parameter call above, or you will have to access its iProperties the long way and dig down through the part document object, PropertySets, PropertySet, Property, Value.

Here is an alternative rule that you might use if accessing the parts parameters and iProperties from the assembly:

(You will need to create a variable for the target part document, and set its value somehow, which is what this first line is attempting to do, first.)

Dim oTargetPart As PartDocument = ThisApplication.Documents.Open("C:\Temp\Part.ipt", False)

If Parameter.Value(oTargetPart.DisplayName,"SEAL_CUSTOM_EXTENTS") = "REQUIRED" Then
	iProperties.Value(oTargetPart.DisplayName, "Project", "Part Number") = "N/A"
	'or
	'oTargetPart.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "N/A"
	
	iProperties.Value(oTargetPart.DisplayName, "Summary", "Keywords") = "RTSM"
	'or
	'oTargetPart.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value = "RTSM"
Else
	iProperties.Value(oTargetPart.DisplayName, "Summary", "Keywords") = "N/A"
	'or
	'oTargetPart.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value = "N/A"
	
	ThisApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
End If

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

If you have time, please... Vote For My IDEAS 💡and Explore My CONTRIBUTIONS

Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 10

JelteDeJong
Mentor
Mentor

if you run the rule from an assembly then "ThisApplication.ActiveDocument" will return the assembly document. You will need to get the part document object. From the code you gave i cant tell how you want to do that. But if you want to convert all part documents you could try the code below

 

Dim doc As AssemblyDocument = ThisApplication.ActiveDocument
For Each refDoc As Document In doc.AllReferencedDocuments
    If refDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
        ThisApplication.ActiveDocument.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
    End If
Next

 

Jelte de Jong
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature


Blog: hjalte.nl - github.com

0 Likes
Message 4 of 10

garethsmithHMNMK
Contributor
Contributor

Thanks but but both methods don't work. Maybe a better explanation:

I have a 2 part assembly. Only 1 part in that assembly is sheet metal. But if that sheet metal part matches a size we keep stock I don't want it to be sheet metal because I'm using a dxf exprt method that looks for sheet metal parts and I don't want it to be exported so simply want to change its part type from sheet metal to a standard part.

0 Likes
Message 5 of 10

garethsmithHMNMK
Contributor
Contributor

Correction. Both parts need be sheet metal, 1 or the other sheet metal or non sheet metal. So it could do with naming the part that I want to change its part type.

0 Likes
Message 6 of 10

WCrihfield
Mentor
Mentor

Just an idea...but have you considered adding a custom iProperty, Attribute, or Parameter (or similar) within the parts in question, then changing its value according to your conditions.  Then alter your other solution that exports all the sheet metal parts, so that it checks the value of this special iProperty, Attribute, or Parameter, before it exports them?  And using this method instead of changing the part back and forth from being a regular part and being a Sheet Metal part?

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 10

garethsmithHMNMK
Contributor
Contributor

Actually yes. My original DXF export method did indeed look at an iproperty value (keyword) to choose whether to export or not. However, I had to look at an alternative export method because designers kept forgetting to add the iproperty value if they added custom parts.

 

Also the export method of just looking at sheet metal would work on older models prior to any iproperty values being set up.

0 Likes
Message 8 of 10

WCrihfield
Mentor
Mentor

I see.  Tough situation.  Here is a more robust and complete version of my earlier code, with several checks in there to help eliminate some possible errors that may be preventing it from working.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisAssembly.Document
For Each oRefDoc As Document In oADoc.AllReferencedDocuments
	If oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oPDoc As PartDocument = ThisApplication.Documents.Open(oRefDoc.FullDocumentName, False)
		For Each oUParam As UserParameter In oPDoc.ComponentDefinition.Parameters.UserParameters
			Dim oExists As Boolean
			If oUParam.Name = "SEAL_CUSTOM_EXTENTS" Then
				oExists = True
				If oUParam.Value = "REQUIRED" Then
					oPDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = "N/A"
					oPDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value = "RTSM"
					Try
						'Check if it is a 'Regular Part', if not change it to one.
						If oPDoc.SubType <> "{4D29B490-49B2-11D0-93C3-7E0706000000}" Then
							oPDoc.SubType = "{4D29B490-49B2-11D0-93C3-7E0706000000}"
						End If
					Catch
						MsgBox("The attempt to change the SubType of " & oPDoc.FullFileName & vbCrLf & _
						"to a 'Regular Part' failed.",,"")
					End Try
				Else 'if that parameter didn't have that value...
					oPDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value = "N/A"
					Try
						'Check if it is a 'Sheet Metal Part', if not change it to one.
						If oPDoc.SubType <> "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}" Then
							oPDoc.SubType = "{9C464203-9BAE-11D3-8BAD-0060B0CE6BB4}"
						End If
					Catch
						MsgBox("The attempt to change the SubType of " & oPDoc.FullFileName & vbCrLf & _
						"to a 'Sheet Metal Part' failed.",,"")
					End Try
				End If
			End If
			If oExists = False Then
				MsgBox("The User Parameter 'SEAL_CUSTOM_EXTENTS' was not found within" & vbCrLf & _
				oPDoc.FullFileName & vbCrLf & _
				"so this part was not processed.", , "Parameter Not Found")
			End If
		Next
		oPDoc.Save
		oPDoc.Close(True)
	End If
Next

Also, just in case you weren't aware, there is another option for checking the document's SubType, that is actually readable/understandable.  There are iProperties named "Document SubType" and "Document SubType Name" within the "Design Tracking Properties" set.  I have found these to be very reliable, and found that they instantly update when changing a part back and forth between regular part and sheet metal part in my testing.  In English, if a part is a regular part, the value of "Document SubType Name" is "Modeling", and if is a sheet metal part, the value is "Sheet Metal".  Although, I am not sure if those values may change to different words for different language Inventor installations.  I have also created an 'Idea' within the Inventor Idea Station to create a 'DocumentSubTypeEnum' to better handle these types of inquiries in a readable, stable way.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 9 of 10

garethsmithHMNMK
Contributor
Contributor

Sorry getting the following errors:

 

Error on Line 2 : 'RuleName' is not a member of 'Autodesk.iLogic.Interfaces.ILowLevelSupport'.
Error on Line 5 : 'ThisAssembly' is not accessible in this context because it is 'Friend'.

0 Likes
Message 10 of 10

WCrihfield
Mentor
Mentor
Accepted solution

OK. Some peoples installs don't seem to like that 'iLogicVb.RuleName' use, even though I've been using it for years without any problems.  It is totally unnecessary though, and can simply be completely eliminated/deleted from that message, if it is causing issues.  You can have that message say anything you want.  It is just meant to inform you if the active document when the rule is started it the right type of document or not, and that if it is the wrong type, it is going to exit the rule without running.

 

If 'ThisAssembly.Document' is causing you problems, try replacing it with 'ThisApplication.ActiveDocument'.

Although I am curious why it is having a problem with it.  Are you running this code as a local iLogic rule, an external iLogic rule, or from Visual Studio?  If you are running it normally as an iLogic rule in Inventor, do you have the "Straight VB code" option turned on or are you using other settings within the header area of the rule?  If so, you may need to turn that option off.  And if necessary, put the whole code within a "Sub Main", then the code, then "End Sub", even though iLogic is supposedly implying those for you in the background.

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes