Custom Properties and Form

Custom Properties and Form

shubham.raturi2308
Advocate Advocate
1,726 Views
16 Replies
Message 1 of 17

Custom Properties and Form

shubham.raturi2308
Advocate
Advocate

Hello Everyone,

Initially, I have a part file without custom properties. Here's the plan:

  1. Create Custom Properties: Define three parameters (Prop1, Prop2, Prop3) with multi-list values using iLogic. I will provide the possible values for each property.

  2. Design a Form: Develop a form incorporating these properties. Implement conditional logic (e.g., selecting a value for Prop1 will filter available options for Prop2, which in turn affects the choices for Prop3).

  3. Automate iProperties Creation: Once the form is completed and 'Export' is selected for custom parameters, it will automatically generate the necessary iProperties.

  4. Integrate with Drawings: Ensure that these custom properties can be referenced in the drawing without being included in the title block.

Thank you for your attention.

Best regards,
Shubham Raturi


@WCrihfield@Curtis_Waguespack , @Michael.Navara @AndrewHumiston 

 

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

AndrewHumiston
Advocate
Advocate

Good morning,

 

Just a few thoughts

 

1) If you are hard coding in the values of the lists, then you may want to create a set of sub-lists based on the choice of Prop1. I.E. you don't want to filter a list based on a choice, you want to drive your choice after selecting Prop1.

 

if you think about it, choosing prop1 should then trigger another list called Prop1b, if you are trying to trigger a set of values from Prop2, the code would quickly become messy.

 

When creating the Parameters Prop1 and so forth, you can set the export when creating the parameter, no need to add an extra step at the end of the form choosing.

 

what do you mean by iproperties being referenced in the drawing, but not in the TB? how do you envision using the properties there?

Message 3 of 17

Curtis_Waguespack
Consultant
Consultant

@shubham.raturi2308 ,

see the attached example, I think it'll give you some ideas on how to proceed.

 

Note there is a rule and form in the part to make the changes there, and a rule a form in the drawing to make the changes from the drawing and push them down to the part.

 

EESignature

Message 4 of 17

Michael.Navara
Advisor
Advisor

@shubham.raturi2308

Below are my comments to your points

 

  1. Create Custom Properties: If you want to define properties with distinct values which depend on others, don't use parameters but implement this functionality outside the model. Don't use parameters, but enforce the iProperty creation and update its values from code. 

  2. Design a Form: If you want to implement any logic in the form, don't use iLogic forms but use WinForms or WPF and design your own dialog using VisualStudio or another  tool. In this case you can implement any logic and dependencies. For example filter possible values for the Prop2 when Prop1 change its value.

  3. Automate iProperties Creation: When the dialog is confirmed, update iProperties using API.

  4. Integrate with Drawings: I don't understand what does it mean. In TitleBlock you can reference iProperties from model. Or you can synchronize properties between model and drawing using API.

Message 5 of 17

shubham.raturi2308
Advocate
Advocate

@Curtis_Waguespack ,

Thank you for your help—it was exactly what I needed. I’m now facing an issue with older files where the required properties are missing, so the form isn’t functioning correctly.

I’m considering using external rules to generate properties and employing external and global forms for selecting values. Do you think this is a viable approach, or would you recommend an alternative solution?

I also observed that you included notes in the drawing sheet linking model parameters and drawing parameters. Is this how you connect properties between the model and the drawing?

@Michael.Navara 

I am not familiar inventor API/VB, but Additionally, I’m interested in learning it. If you could suggest some useful articles, I would greatly appreciate it.

 

0 Likes
Message 6 of 17

AndrewHumiston
Advocate
Advocate

Morning,

 

Here is a code to check a custom iprop and if not there create it.

 

let me know what you think:

 

Function:

 

MakeProp("ItemCatagory")

Function MakeProp(Prop)

	'set ref to active doc
	ActiveDoc = ThisApplication.ActiveDocument
	'check to see if there are any iprops and if not add one, and if so then check to see if iprop exists and if not make it
	Select Case ActiveDoc.PropertySets.Item("Inventor User Defined Properties").Count
		Case 0
			Call ActiveDoc.PropertySets.Item("Inventor User Defined Properties").Add("", Prop)
		Case Else
			For Count = 1 To ActiveDoc.PropertySets.Item("Inventor User Defined Properties").Count
				If ActiveDoc.PropertySets.Item("Inventor User Defined Properties").Item(Count).Name = Prop Then Exit For
				If Count = ActiveDoc.PropertySets.Item("Inventor User Defined Properties").Count Then
				Call ActiveDoc.PropertySets.Item("Inventor User Defined Properties").Add("", Prop)
				End If
			Next
	End Select

End Function

use makeprop(String) to call the make prop code.

 

hope this gets you closer! 

Message 7 of 17

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@shubham.raturi2308 wrote:


...older files where the required properties are missing, so the form isn’t functioning correctly.

I’m considering using external rules to generate properties and employing external and global forms for selecting values. Do you think this is a viable approach, or would you recommend an alternative solution?

 


Hi @shubham.raturi2308 , you've said properties above, but the form uses parameters for the controls, so I assume you meant parameters.

 

What I would typically do is make the rule an external rule as you mentioned, and then make the form a global ( external ) form.

 

And then have another external rule that creates the parameters if not found (see example below). I add this rule to the After Open Event trigger, so that it is run when a file is open. In the example below I've added this for all part files:

 

Curtis_Waguespack_0-1723557116697.png

 

 

Dim oDoc As PartDocument = ThisDoc.Document
Dim ValueMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
'parameter name and default value
ValueMap.Add("Prop1", "Up")
ValueMap.Add("Prop2", "Small")
ValueMap.Add("Prop3", "Friday")

For i = 1 To ValueMap.Count
	PropName = ValueMap.Name(i)
	PropValue = ValueMap.Value(PropName)

	Try
		oTest = oDoc.ComponentDefinition.Parameters.UserParameters.Item(PropName)
	Catch
		oDoc.ComponentDefinition.Parameters.UserParameters.AddByValue(PropName, PropValue, UnitsTypeEnum.kTextUnits)
	End Try
	
	iProperties.Value("Custom", PropName) = PropValue
Next

'set default lists
MultiValue.SetList("Prop1", "Up", "Down")
MultiValue.SetList("Prop2", "Extra Large", "Large", "Medium", "Small")
MultiValue.SetList("Prop3", "Monday", "Teuesday", "Wednesday", "Thursday", "Friday")

InventorVb.DocumentUpdate()

 

 

 

EESignature

Message 8 of 17

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@shubham.raturi2308 wrote:

I also observed that you included notes in the drawing sheet linking model parameters and drawing parameters. Is this how you connect properties between the model and the drawing?


There are a few ways we can do this. In this case since I had parameters set up for use in the form, there were available for use from the model in the drawing.

 

If we only had properties, and not the corresponding parameters then we could just use the properties vs the parameters

Curtis_Waguespack_0-1723557592026.png

 


You can also use the Copy Model iProperty Settings option in the document settings to synch the model and drawing properties. Typically we'd set this up in the drawing template.

Curtis_Waguespack_1-1723557698416.png

 



EESignature

Message 9 of 17

Curtis_Waguespack
Consultant
Consultant

@AndrewHumiston , Just a quick tip ( that I overlooked for many years), the iLogic iProperties.Values function will automatically create a property if it does not exist. So in this example, if Foo does not exist, it will be created and the value set with just this one line.

 

If we're working with add-ins or straight API calls, and not iLogic then your example is an excellent way to go.

 

iProperties.Value("Custom", "Foo") = "Hello World"

 

EESignature

Message 10 of 17

AndrewHumiston
Advocate
Advocate

Good to know!

 

that is code adapted from VBA, but i love learning new methods.

0 Likes
Message 11 of 17

shubham.raturi2308
Advocate
Advocate

@Curtis_Waguespack 

This approach worked effectively; however, I encountered an issue where only the parameters were being updated, while the properties remained at their default values. To address this, I added a rule triggered after saving:

 

iProperties.Value("Custom", "Prop1") = Parameter("Prop1")

 

Nevertheless, I've encountered another challenge. I need to create two separate sets of rules: one for parts and another for assemblies (Any changes or logic if only one rule can do it), as we're using:

 

 

Dim oDoc As PartDocument = ThisDoc.Document

 

Given that the files are old, I’ve successfully created properties for parts and assemblies. However, applying this to drawings will be very manual, requiring individual updates for each file. Do you have any suggestions on how to streamline this?"

0 Likes
Message 12 of 17

AndrewHumiston
Advocate
Advocate

you could add handling in the begining of the rule to run one set of information based on the file type.

Message 13 of 17

Curtis_Waguespack
Consultant
Consultant
Accepted solution

@shubham.raturi2308 

 

If you're running this in the models (parts and assemblies) , I think you can just change that line to this, to have a rule to run in both

Dim oDoc As Document = ThisDoc.Document

 

 

EESignature

Message 14 of 17

shubham.raturi2308
Advocate
Advocate

@AndrewHumiston 

Added "Check document" as suggested in the start now, the same rule is working on part and Assembly.

 

' Get the active document
Dim oDoc As Document = ThisApplication.ActiveDocument

' Declare the ComponentDefinition object
Dim oCompDef As ComponentDefinition

' Check the document type and set the correct object
If oDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
    Dim oPartDoc As PartDocument = oDoc
    oCompDef = oPartDoc.ComponentDefinition
ElseIf oDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
    Dim oAsmDoc As AssemblyDocument = oDoc
    oCompDef = oAsmDoc.ComponentDefinition
ElseIf oDoc.DocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
    Dim oDrawDoc As DrawingDocument = oDoc
    Dim oSheet As Sheet = oDrawDoc.Sheets.Item(1)
    oCompDef = oSheet.DrawingViews.Item(1).ReferencedDocument.ComponentDefinition
End If

' Create a NameValueMap to store parameter names and default values
Dim ValueMap As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap()
' Parameter name and default value
ValueMap.Add("Prop1", "Up")
ValueMap.Add("Prop2", "Small")
ValueMap.Add("Prop3", "Friday")

For i = 1 To ValueMap.Count
    PropName = ValueMap.Name(i)
    PropValue = ValueMap.Value(PropName)

    Try
        ' Try to get the existing parameter
        oTest = oCompDef.Parameters.UserParameters.Item(PropName)
    Catch
        ' If the parameter doesn't exist, add it
        oCompDef.Parameters.UserParameters.AddByValue(PropName, PropValue, UnitsTypeEnum.kTextUnits)
    End Try
    
    ' Set the iProperty value
    iProperties.Value("Custom", PropName) = PropValue
Next

' Set default lists
MultiValue.SetList("Prop1", "Up", "Down")
MultiValue.SetList("Prop2", "Extra Large", "Large", "Medium", "Small")
MultiValue.SetList("Prop3", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday")

' Update the document
InventorVb.DocumentUpdate()

 


Still not sure how to tackle the drawing properties problem.

0 Likes
Message 15 of 17

shubham.raturi2308
Advocate
Advocate

This single line merges 7 lines into one.  Just wow.

Dim oDoc As Document = ThisDoc.Document

 

Message 16 of 17

shubham.raturi2308
Advocate
Advocate

@Michael.Navara 

"you can synchronize properties between model and drawing using API"

Can you give an example?

0 Likes
Message 17 of 17

Michael.Navara
Advisor
Advisor

Full implementation you can see and test here.

The minimalistic implementation can look like this rule. The code needs to be run from drawing and it copy iProperty values from model to drawing.

 

Dim drw As DrawingDocument = ThisDrawing.Document
Dim model = ThisDrawing.ModelDocument.DisplayName

iProperties.Value(drw, "Project", "Description") = iProperties.Value(model, "Project", "Description")
iProperties.Value(drw, "Custom", "PropertyName") = iProperties.Value(model, "Custom", "PropertyName")