ilogic - Copy iproperties from assembly to various parts

ilogic - Copy iproperties from assembly to various parts

Anonymous
Not applicable
4,422 Views
30 Replies
Message 1 of 31

ilogic - Copy iproperties from assembly to various parts

Anonymous
Not applicable

Hi.

I have an issue and couldn't find an exact answear.

 

I want to copy iproperty value form assembly to all sub-components (assemblies, parts and parts of asemblies).

Amount of this sub-components is various.

Names of this sub-components are various.

There can be many levels of assemblies.

I want this ilogic rule to be run from main assembly.

This iproperty might be a custom property (let's name it NR).

 

Could You help please?

 

 

0 Likes
Accepted solutions (1)
4,423 Views
30 Replies
Replies (30)
Message 2 of 31

johnsonshiue
Community Manager
Community Manager

Hi Tomasz,

 

I believe this is highly doable in iLogic. You can also do it manually. You just need open the top-level assembly BOM table. Add the iProperty as a column to the table. Simply drag the value fro top to bottom like in Excel. Then all components in this assembly will get the iProperty. However, all affected component files will need to be saved.

Many thanks!



Johnson Shiue (johnson.shiue@autodesk.com)
Software Test Engineer
0 Likes
Message 3 of 31

Anonymous
Not applicable

Thanks for Your reply.

 

I know this possibility and I often use BOM table for many purposes.

This time I need to automate this process.

I wish it would be one ilogic rule.

0 Likes
Message 4 of 31

HermJan.Otterman
Advisor
Advisor

Look in the API help of inventor, search on Property object,

you'll find two exampls,

 

one to read/get parameters

one to set.

all you need to do is go through all parts, you can use : AssemblyDocument.AllReferencedDocuments to create the loop

 

Get value of iProperty

Public Sub GetPropertySample()
    ' Get the active document.
    Dim invDoc As Document
    Set invDoc = ThisApplication.ActiveDocument
    
    ' Get the design tracking property set.
    Dim invDesignInfo As PropertySet
    Set invDesignInfo = invDoc.PropertySets.Item("Design Tracking Properties")
    
    ' Get the part number property.
    Dim invPartNumberProperty As Property
    Set invPartNumberProperty = invDesignInfo.Item("Part Number")
    
    MsgBox "Part Number: " & invPartNumberProperty.value
End Sub

 

 

 

Create or update custom iProperty

Public Sub UpdateVolume()
    ' Get the active part document.
    Dim invPartDoc As PartDocument
    Set invPartDoc = ThisApplication.ActiveDocument

    ' Get the volume of the part. This will be returned in
    ' cubic centimeters.
    Dim dVolume As Double
    dVolume = invPartDoc.ComponentDefinition.MassProperties.Volume

    ' Get the UnitsOfMeasure object which is used to do unit conversions.
    Dim oUOM As UnitsOfMeasure
    Set oUOM = invPartDoc.UnitsOfMeasure

    ' Convert the volume to the current document units.
    Dim strVolume As String
    strVolume = oUOM.GetStringFromValue(dVolume, oUOM.GetStringFromType(oUOM.LengthUnits) & "^3")

    ' Get the custom property set.
    Dim invCustomPropertySet As PropertySet
    Set invCustomPropertySet = invPartDoc.PropertySets.Item("Inventor User Defined Properties")

    ' Attempt to get an existing custom property named "Volume".
    On Error Resume Next
    Dim invVolumeProperty As Property
    Set invVolumeProperty = invCustomPropertySet.Item("Volume")
    If Err.Number <> 0 Then
        ' Failed to get the property, which means it doesn't exist
        ' so we'll create it.
        Call invCustomPropertySet.Add(strVolume, "Volume")
    Else
        ' Got the property so update the value.
        invVolumeProperty.value = strVolume
    End If
End Sub

 

 

 

 

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 5 of 31

Anonymous
Not applicable
0 Likes
Message 6 of 31

j_weber
Mentor
Mentor

Hi 

I'm not a great programmer, but you can transform the vba code to iLogic. 

 

It looks like this. 

 

'Update Volume
    ' Get the active part document.
    Dim invPartDoc As PartDocument
    invPartDoc = ThisApplication.ActiveDocument

    ' Get the volume of the part. This will be returned in
    ' cubic centimeters.
    Dim dVolume As Double
    dVolume = invPartDoc.ComponentDefinition.MassProperties.Volume

    ' Get the UnitsOfMeasure object which is used to do unit conversions.
    Dim oUOM As UnitsOfMeasure
    oUOM = invPartDoc.UnitsOfMeasure

    ' Convert the volume to the current document units.
    Dim strVolume As String
    strVolume = oUOM.GetStringFromValue(dVolume, oUOM.GetStringFromType(oUOM.LengthUnits) & "^3")

    ' Get the custom property set.
    Dim invCustomPropertySet As PropertySet
    invCustomPropertySet = invPartDoc.PropertySets.Item("Inventor User Defined Properties")

    ' Attempt to get an existing custom property named "Volume".
    On Error Resume Next
    Dim invVolumeProperty As [Property]
    invVolumeProperty = invCustomPropertySet.Item("Volume")
    If Err.Number <> 0 Then
        ' Failed to get the property, which means it doesn't exist
        ' so we'll create it.
        Call invCustomPropertySet.Add(strVolume, "Volume")
    Else
        ' Got the property so update the value.
        invVolumeProperty.Value = strVolume
    End If

 

And the second one like this

 

'GetPropertySample

	' Get the active document.
    Dim invDoc As Document
    invDoc = ThisApplication.ActiveDocument
    
    ' Get the design tracking property set.
    Dim invDesignInfo As PropertySet
    invDesignInfo = invDoc.PropertySets.Item("Design Tracking Properties")
    
    ' Get the part number property.
    Dim invPartNumberProperty As [Property]
    invPartNumberProperty = invDesignInfo.Item("Part Number")
    
    MsgBox ("Part Number: " & invPartNumberProperty.value)

Hope it helps




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





0 Likes
Message 7 of 31

Anonymous
Not applicable

Thanks for reply.

 

First window doesn't work and the problem is in first 4 verses

 

Second window seems to work, but I need it to work with a custom property (for example "NR")

0 Likes
Message 8 of 31

j_weber
Mentor
Mentor

If you only have informations about property value you can create a form. 

In the form you can drag'n'drop the properties you want to see form the list on the left side in the window of the right side. 

After that you can open the form with the name. 

 

To do this you doesn't need create a rule or something else. 

 

Very easy and very helpfull

 

image.png

 

image.png




Jörg Weber
CAD Systemtechniker für AutoCAD, Inventor, Vault





0 Likes
Message 9 of 31

Anonymous
Not applicable

This Form-method will help.

All I need is to insert a value (for example using a form) and the pass it on to all subcomponents.

 

For example:

- My custom property is called "NR"

- I insert NR's value - 999 (can be inserted through the form)

- I want all subcomponents to have a custom property "NR" with value 999.

 

I found a partial solution elsewhere:

 

oAssyDoc = ThisDoc.Document
compdef = oAssyDoc.ComponentDefinition


For Each occ In compdef.Occurrences.AllLeafOccurrences

currentBOMStructure = occ.BOMStructure

iProperties.Value(occ.Name, "Custom", "NR") = iProperties.Value("Custom", "NR")


Next occ

This solution works however only with part-elements - firts level parts and parts inside assemblies.

I need to expand this rule, so that both parts and assemblies get this property.

0 Likes
Message 10 of 31

HermJan.Otterman
Advisor
Advisor

for the loop try this:

 

 

 

SyntaxEditor Code Snippet

        Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
        Dim AllRefDocs As DocumentsEnumerator = oAssyDoc.AllReferencedDocuments
        Dim oDoc As Inventor.Document = Nothing

			' Input
			strVolume = InputBox("Prompt", "Title", "Default Entry")


        For Each oDoc In AllRefDocs

            'set your properties

            ' Get the custom property set.
            Dim invCustomPropertySet As PropertySet
            invCustomPropertySet = oDoc.PropertySets.Item("Inventor User Defined Properties")

            'if you have a CUSTOM property called "Volume" then
            Dim invVolumeProperty As Inventor.Property
     		invVolumeProperty = invCustomPropertySet.Item("Volume")
			
'			' Input
'			strVolume = InputBox("Prompt", "Title", "Default Entry")


            ' Got the property so update the value. .... SET the value
            invVolumeProperty.value = strVolume

        Next
If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


Message 11 of 31

Anonymous
Not applicable

The result is:

HRESULT: 0x80070003(E_FAIL)

0 Likes
Message 12 of 31

HermJan.Otterman
Advisor
Advisor

probably that is because there is no custom property called "Volume" in the parts.

 

in my first post I posted code from the help, parts of it I used in this rule.

in the first post there are some lines if the parameter does not exist, it will create it, so add those lines if you don't want to create the custom parameters up front.

 

the way I see this forum is to help people with questions on programming, and not to create programs for people..

so see this as a help to create your own program, and learn from it.

 

I hope you can continue with your challenge.

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 13 of 31

Anonymous
Not applicable

Thanks for reply.

I understand Your vision of this forum and don't want to change it, but

I am a mechanical designer with 0 experience/knowledge in programming.

Transfering examples to my demands is not se easy for me.

 

For now my working solution looks like this:

 

        Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
        Dim AllRefDocs As DocumentsEnumerator = oAssyDoc.AllReferencedDocuments
        Dim oDoc As Inventor.Document = Nothing
    
            strNR = iProperties.Value("Project", "Project")
            
        For Each oDoc In AllRefDocs
                
            Dim invDesignInfo As PropertySet
            invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties")
    
            Dim invPartNumberProperty As [Property]
            invProjectProperty = invDesignInfo.Item("Project")
   
            invProjectProperty.Value = strNR
    
        Next

 

This rule transfers <Project> property from iproperties to all subcomponents.

That is easier for me since a property <Project> does always exist.

Setting <Project> I do through Form.

 

If someone can transfer this rule for custom properties (for example NR), I would be grateful.

Please notice that this rule must include creating a custom property named NR in each subcomponent.

0 Likes
Message 14 of 31

HermJan.Otterman
Advisor
Advisor

I understand.

 

look at this link:

http://modthemachine.typepad.com/files/ipropertiesandparameters.pdf

 

on page 13 you see an overview for the different properties

you can change the next line in the code to get the properties you want

 

invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties")

If this answers your question then please select "Accept as Solution"
Kudo's are also appreciated Smiley Wink

Succes on your project, and have a nice day

Herm Jan


0 Likes
Message 15 of 31

tecnico
Contributor
Contributor

Hi, I tried to use the last rule, but it gives me the following error: HRESULT: 0x80004005 (E_FAIL), I tried to put it in an assembly of assemblies, I don't know if this could have affected the execution of this one.

0 Likes
Message 16 of 31

A.Acheson
Mentor
Mentor

I would first check if all iproperties you are trying to reference are existing. Can you post the rule you are using? 

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
0 Likes
Message 17 of 31

tecnico
Contributor
Contributor

I simply copied and pasted the last rule written by Tomasz. dabrowskIUGC2B, when I tried it on a new assembly with only 3 elements it worked correctly, but when I inserted it in a more complex assembly with assemblies inside it gave me that error that I have written previously

iProperties.Value("Project", "Project") = InputBox("Riferimento al progetto", "Progetto", "Default Entry")

	Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim AllRefDocs As DocumentsEnumerator = oAssyDoc.AllReferencedDocuments
    Dim oDoc As Inventor.Document = Nothing

        strNR = iProperties.Value("Project", "Project")
        
    For Each oDoc In AllRefDocs
            
        Dim invDesignInfo As PropertySet
        invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties")

        Dim invPartNumberProperty As [Property]
        invProjectProperty = invDesignInfo.Item("Project")

        invProjectProperty.Value = strNR
    
    Next
0 Likes
Message 18 of 31

Anonymous
Not applicable

I started this topic long time ago, when my experience in iLogic was poor.

Now I think I can solve this problem.

My opinion is that it crashes because of Content Center or library files - you cannot access them and change their properties. You must skip them. So my code checks the path of each document to find if it is from CC or Libraries.

iProperties.Value("Project", "Project") = InputBox("Riferimento al progetto", "Progetto", "Default Entry")

	Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim AllRefDocs As DocumentsEnumerator = oAssyDoc.AllReferencedDocuments
    Dim oDoc As Inventor.Document = Nothing
	Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
	Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath
	Dim i As Integer
	Dim isCC As Boolean = False
	Dim isLibrary As Boolean = False

        Dim strNR as string = iProperties.Value("Project", "Project")
        
    For Each oDoc In AllRefDocs
		
		For i = 1 To oProjectMgr.ActiveDesignProject.LibraryPaths.Count
			If oDoc.FullFileName.Contains(oProjectMgr.ActiveDesignProject.LibraryPaths.Item(i).Path) = True Then 
				isLibrary = True
				Exit For
				End If
		Next
		
		If oDoc.FullFileName.Contains(CCPath) = True Then
			isCC = True
		End If
			
		If isCC = False And isLibrary = False Then

	        Dim invDesignInfo As PropertySet
	        invDesignInfo = oDoc.PropertySets.Item("Design Tracking Properties")

	        Dim invProjectProperty As [Property]
	        invProjectProperty = invDesignInfo.Item("Project")

	        invProjectProperty.Value = strNR
		End If
		
    	isCC = False
		isLibrary = False
    Next

 

0 Likes
Message 19 of 31

Anonymous
Not applicable
Accepted solution

I aslo add another code for custom properties - which was the case of this topic.

This code wil:

- skip all documents form CC and Libraries

- check if desired custom property exist and if to - create one

- copy value of this custom property form top level assembly to each document

	Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
    Dim AllRefDocs As DocumentsEnumerator = oAssyDoc.AllReferencedDocuments
    Dim oDoc As Inventor.Document = Nothing
	Dim oProjectMgr As DesignProjectManager = ThisApplication.DesignProjectManager
	Dim CCPath As String = oProjectMgr.ActiveDesignProject.ContentCenterPath
	Dim i As Integer
	Dim isCC As Boolean = False
	Dim isLibrary As Boolean = False
	Dim PropertyName As String = "NR" 'here is your property name
    Dim strNR As String = iProperties.Value("Custom", PropertyName)
        
    For Each oDoc In AllRefDocs
		
		For i = 1 To oProjectMgr.ActiveDesignProject.LibraryPaths.Count
			If oDoc.FullFileName.Contains(oProjectMgr.ActiveDesignProject.LibraryPaths.Item(i).Path) = True Then 
				isLibrary = True
				Exit For
				End If
		Next
		
		If oDoc.FullFileName.Contains(CCPath) = True Then
			isCC = True
		End If
			
		If isCC = False And isLibrary = False Then

	        Dim invCustom As PropertySet
	        invCustom = oDoc.PropertySets.Item("Inventor User Defined Properties")

	        Dim invMyProperty As [Property]
			Try
	        	invMyProperty = invCustom.Item(PropertyName)
				invMyProperty.Value = strNR
			Catch
				invCustom.Add(strNR,PropertyName)
			End Try
		End If
		
    	isCC = False
		isLibrary = False
    Next

 

0 Likes
Message 20 of 31

tecnico
Contributor
Contributor

EXACT! One of my biggest problems is that you don't want it to change the files that are purchased from the list or those of the content center, so with this code it is possible to change that iproperteis only to what is normal in the list?

0 Likes