Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

iLogic transcription custom properties from assembly to all subassemblies/parts

Anonymous

iLogic transcription custom properties from assembly to all subassemblies/parts

Anonymous
Not applicable

Hello All,


I need get from "Custom" properties in assembly two value "Assembly Name" and "Assembly Nr" and write to all subassemblies and parts used in this assembly.

Bellow you can see my experiment of code for "Assembly Name", but if i try anything I get back only "(Exception from HRESULT: 0x80004005 (E_FAIL))"

 

Can anyone help me?

Kind Regards,

Martin Hule.

Dim oAssyDoc As AssemblyDocument = ThisApplication.ActiveDocument
Dim AllRefDocs As DocumentsEnumerator = oAssyDoc.AllReferencedDocuments
Dim oDoc As Inventor.Document = Nothing
    
            strNR = iProperties.Value("Custom", "Assembly Name")
            
        For Each oDoc In AllRefDocs
                
            Dim invDesignInfo As PropertySet
            invDesignInfo = oDoc.PropertySets.Item("Inventor User Defined Properties")
    
            Dim invAssemblyNameProperty As Inventor.Property
     		invAssemblyNameProperty = invDesignInfo.Item("Assembly Name")
   
    
	
        Next

 

0 Likes
Reply
Accepted solutions (2)
595 Views
5 Replies
Replies (5)

JhoelForshav
Mentor
Mentor
Accepted solution

Hi @Anonymous 

Try this 🙂

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oCustomProps As PropertySet = oAsm.PropertySets.Item("Inventor User Defined Properties")
Dim AssemblyName As String
Dim AssemblyNr As String
Try
AssemblyName  = oCustomProps.Item("Assembly Name").Value
AssemblyNr = oCustomProps.Item("Assembly Nr").Value
Catch
	MessageBox.Show("Make sure the assembly has custom properties Assembly Name and Assembly nr", _
	"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Exit Sub
End Try
For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	If oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		oCustomProps = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
		Try
			oCustomProps.Item("Assembly Name").Value = AssemblyName
		Catch
			oCustomProps.Add(AssemblyName, "Assembly Name")
		End Try
		Try
			oCustomProps.Item("Assembly Nr").Value = AssemblyNr
		Catch
			oCustomProps.Add(AssemblyNr, "Assembly Nr")
		End Try
	End If
Next
0 Likes

Anonymous
Not applicable

Hi @JhoelForshav ,

 

Thank you for your replay, 

 

But if I try I get again (Exception from HRESULT: 0x80004005 (E_FAIL)).

 

More Info:

System.Runtime.InteropServices.COMException (0x80004005): Nespecifikovaná chyba (Exception from HRESULT: 0x80004005 (E_FAIL))
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Inventor.PropertySet.Add(Object PropValue, Object Name, Object PropId)
at ThisRule.Main()
at Autodesk.iLogic.Exec.AppDomExec.ExecRuleInAssembly(Assembly assem)
at iLogic.RuleEvalContainer.ExecRuleEval(String execRule)

 

0 Likes

Anonymous
Not applicable

Hi @JhoelForshav ,

 

I found where is the problem. I must have prepared this two custom properties ("Assembly Name", "Assembly Nr") in all parts, after that is fantastic. It is possible create this custom properties in all Sub-Assemblies and parts trough the run this rule?

 

Kind Regards,

Martin Hule.

0 Likes

JhoelForshav
Mentor
Mentor

@Anonymous 

You shouldn't have to do that. The code is written so that if the property doesn't exist already it'll be created. I don't know why you got this error. I've tried it on a lot of assemblies now and it runs as expected without any errors every time...

0 Likes

Anonymous
Not applicable
Accepted solution

@JhoelForshav 

 

It is strange, but I make this little changes and now it work realy good! Thank you!

 

Dim oAsm As AssemblyDocument = ThisDoc.Document
Dim oCustomProps As PropertySet = oAsm.PropertySets.Item("Inventor User Defined Properties")
Dim AssemblyName As String
Dim AssemblyNr As String

Try
AssemblyName  = iProperties.Value("Custom", "Assembly Name")
AssemblyNr = iProperties.Value("Custom", "Assembly Nr")
Catch
	MessageBox.Show("Make sure the assembly has custom properties Assembly Name and Assembly nr", _
	"Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
	Exit Sub
End Try

For Each oRefDoc As Document In oAsm.AllReferencedDocuments
	If oAsm.ComponentDefinition.Occurrences.AllReferencedOccurrences(oRefDoc).Count > 0
		oCustomProps = oRefDoc.PropertySets.Item("Inventor User Defined Properties")
		Try
			oCustomProps.Item("Assembly Name").Value = iProperties.Value("Custom", "Assembly Name")
		Catch
			oCustomProps.Add(AssemblyName, "Assembly Name")
		End Try
		Try
			oCustomProps.Item("Assembly Nr").Value = iProperties.Value("Custom", "Assembly Nr")
		Catch
			oCustomProps.Add(AssemblyNr, "Assembly Nr")
		End Try
	End If
Next
0 Likes