check export parameter box

check export parameter box

Anonymous
Not applicable
1,226 Views
6 Replies
Message 1 of 7

check export parameter box

Anonymous
Not applicable

hi

 

I want to use ilogic to check if a user parameter exists, if it does exist then the user parameter "export parameter box should be "checked"

 

can anyone help with the line of code that checks the box?

 

thanks to all..

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument

Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition
Dim oParameter As Parameter

'Check if Param Exists
Try
If Parameter("G_W") = Parameter("G_W") Then

<Enter line of code to check box>
End If Catch MessageBox.Show("Param doesn't exist", "Title") End Try

 

user param.jpg

0 Likes
Accepted solutions (1)
1,227 Views
6 Replies
Replies (6)
Message 2 of 7

smilinger
Advisor
Advisor
Accepted solution
Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

'Check if parameter exist
If oCompDef.Parameters.IsExpressionValid("G_W", "mm") Then
	Dim oParameter As Inventor.Parameter = oCompDef.Parameters("G_W")
	
	'Export parameter as iProperty
	oParameter.ExposedAsProperty = True
	
	'Set custom iProperty format
	oParameter.CustomPropertyFormat.ShowTrailingZeros = False
	oParameter.CustomPropertyFormat.ShowUnitsString = False
End If
Message 3 of 7

smilinger
Advisor
Advisor

For more parameters:

 

Dim oDoc As PartDocument
oDoc = ThisApplication.ActiveDocument
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

For Each parameterName In {"Thickness", "G_L", "G_W"}
	'Check if parameter exist
	If oCompDef.Parameters.IsExpressionValid(parameterName, "mm") Then
		Dim oParameter As Inventor.Parameter = oCompDef.Parameters(parameterName)
		
		'Export parameter as iProperty
		oParameter.ExposedAsProperty = True
		
		'Set custom iProperty format
		oParameter.CustomPropertyFormat.ShowTrailingZeros = False
		oParameter.CustomPropertyFormat.ShowUnitsString = False
	End If
Next
Message 4 of 7

myronHBBUW
Contributor
Contributor

@smilinger ,

 

is there a way to run this rule from an assembly?

and that it skippes library files

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

Hi @myronHBBUW.  Here is some code that could be used from an assembly, that will iterate down through all levels of referenced documents, looking for a specifically named parameter, and if found, attempts to ensure it is set to 'Exposed/Exported', so that a matching custom iProperty will be created/exist for it.  I am using two filters to help avoid 'library' files.  One filter this is using is the Document.IsModifiable property, and another filter is checking whether or not any parts it encounters are associated with the Content Center, by checking its IsContentMember property.  This is definitely the longer code way of doing this task, because it is doing the task entirely by API code (without using any iLogic shortcut snippets...except for 'ThisDoc.Document').

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("An Assembly Document must be active for this rule to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oADoc As AssemblyDocument = ThisDoc.Document
Dim oRefDocs As DocumentsEnumerator = oADoc.AllReferencedDocuments
If oRefDocs.Count = 0 Then Exit Sub
For Each oRefDoc As Document In oRefDocs
	If Not oRefDoc.IsModifiable Then Continue For 'skip to next oRefDoc
	Dim oParams As Parameters = Nothing
	If oRefDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
		Dim oRefADoc As AssemblyDocument = oRefDoc
		oParams = oRefADoc.ComponentDefinition.Parameters
	ElseIf oRefDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
		Dim oRefPDoc As PartDocument = oRefDoc
		If oRefPDoc.ComponentDefinition.IsContentMember Then Continue For
		oParams = oRefPDoc.ComponentDefinition.Parameters
	Else : Continue For : End If
	For Each oParam As Inventor.Parameter In oParams
		If oParam.Name = "G_W" Then
			Try : oParam.ExposedAsProperty = True: Catch : End Try
		End If
	Next
	If oRefDoc.RequiresUpdate Then oRefDoc.Update2(True)
	If oRefDoc.Dirty Then oRefDoc.Save2(False)
Next
If oADoc.RequiresUpdate Then oADoc.Update2(True)
If oADoc.Dirty Then oADoc.Save2(False)

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

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7

myronHBBUW
Contributor
Contributor

@WCrihfield 

 

Great this works!

Can you modify it a bit to uncheck trailing zeros, unitstring and leading zeros?

0 Likes
Message 7 of 7

WCrihfield
Mentor
Mentor

Hi @myronHBBUW.  Sure.  To add that extra functionality, you could simply replace the following line of code:

Try : oParam.ExposedAsProperty = True: Catch : End Try

...with this block of code:

Try
	oParam.ExposedAsProperty = True
	oCPF = oParam.CustomPropertyFormat
	oCPF.ShowLeadingZeros = False
	oCPF.ShowTrailingZeros = False
	oCPF.ShowUnitsString = False
Catch
End Try

When you right-click on a parameter row in the Parameters dialog box, after you have checked the box under "Export Parameter" column, you will see an option within the right-click menu called "Custom Property Format...".  When you choose that, you will see the "Custom Property Format" dialog.  Everything you see in that dialog can be controlled by code, except maybe the checkbox at the very bottom that says "Apply to existing comparable parameters".  You will notice that if you change the property type to number, instead of text, the Format options, and the options on the right get greyed out, because they do not apply anymore.  Since we can not export Text or Boolean type user parameters, I almost always export my parameters as number type properties, instead of text, so I only set Property Type, Units, & Precision in my own codes, for that purpose...just for your added information, and future consideration.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)