Push iProperty Values To Another File

kwalker1
Enthusiast
Enthusiast

Push iProperty Values To Another File

kwalker1
Enthusiast
Enthusiast

I have an iLogic rule in an assembly file which shrinkwraps the model when the document is closed.

But I would also like to push some of the assemblies' iproperties to the newly created shrinkwrapped part file.

 

I have tried the following code but I get the error:

iProperties:The document named "C:\Inventor Projects\WALKWAYS\WW - WALKWAY ASSEMBLY (SHRINKWRAPPED).ipt" was not found.

even though the file is there in the correct location.

Can anyone see where I'm going wrong?

 

Dim docFName As String
Dim oDoc As Inventor.Document = docFName
docFName = ThisDoc.PathAndFileName(False)& " (SHRINKWRAPPED).ipt"
iProperties.Value(docFName, "Project", "Description") = iProperties.Value("Project", "Description")
iProperties.Value(docFName, "Custom", "DRAWING No.") = iProperties.Value("Custom", "DRAWING No.")

 

The full iLogic code for the shrinkwrap that I'm trying to use above snippet in is as follows:

 

Sub Main()

	'CHECK ACTIVE DOCUMENT IS THE SAME DOCUMENT THAT CONTAINS THIS iLOGIC RULE.
	'THIS CHECK IS TO PREVENT THE RULE FROM ATTEMPTING TO RUN WHEN CLOSING THE DRAWING SHEET.
	Dim activeDoc As Document = ThisApplication.ActiveDocument
	If Not activeDoc Is ThisDoc.Document Then
	Exit Sub
	Else
	
		Question = MessageBox.Show("Do you wish to shrinkwrap the Walkway Assembly now for use in the General Arrangement?", "Walkway Assembly",MessageBoxButtons.YesNo)
		If Question = vbYes Then
		
		Dim oAsmCompDef As AssemblyComponentDefinition
		oAsmCompDef = ThisApplication.ActiveDocument.ComponentDefinition
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
		
		Try
			Dim g_App As Inventor.InventorServer = ThisApplication
			Dim AssDoc as Inventor.AssemblyDocument= ThisDoc.Document
			
			'CREATE A NEW PART DOCUMENT THAT WILL BE THE SHRINKWRAP SUBSTITUTE
			Dim oPartDoc As PartDocument
			oPartDoc = g_App.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
			
			Dim oPartDef As PartComponentDefinition
			oPartDef = oPartDoc.ComponentDefinition
			
			Dim oDerivedAssemblyDef As DerivedAssemblyDefinition
			oDerivedAssemblyDef = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(AssDoc.FullDocumentName)
			'SET VARIOUS SHRINKWRAP RELATED OPTIONS
			oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
			oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
			oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
			oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
			oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
			Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
			Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)
			Dim oDerivedAss As DerivedAssemblyComponent
			oDerivedAss = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
			Call oDerivedAss.BreakLinkToFile()
									
			'SAVE THE PART
			Dim partname As String=ThisDoc.PathAndFileName(False)& " (SHRINKWRAPPED).ipt"
			ThisApplication.ActiveView.Fit
			ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute
			Call oPartDoc.SaveAs(partname ,  False)
			
		Catch ex As Exception
			ErrorMessage = "Error creating ipt file."
		End Try
		
		'Try
			Dim docFName As String
			Dim oDoc As Inventor.Document = docFName
			docFName = ThisDoc.PathAndFileName(False)& " (SHRINKWRAPPED).ipt"
			iProperties.Value(docFName, "Project", "Description") = iProperties.Value("Project", "Description")
			iProperties.Value(docFName, "Custom", "DRAWING No.") = iProperties.Value("Custom", "DRAWING No.")
		'Catch
		'End Try
		
		oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
						
		Else
		'CLOSE MESSAGE BOX AND DO NOTHING
		End If
		
	End If

End Sub
0 Likes
Reply
Accepted solutions (1)
1,055 Views
5 Replies
Replies (5)

Owner2229
Advisor
Advisor

Here you go:

 

 

Sub Main()
    Dim aDoc As Document = ThisApplication.ActiveDocument
    If aDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub 'Assembly documents only
    
    Question = MessageBox.Show("Do you wish to shrinkwrap the Walkway Assembly now for use in the General Arrangement?", "Walkway Assembly",MessageBoxButtons.YesNo)
    If Question <> vbYes Then
        Exit Sub 'Exit
    End If
    
    Dim oAsmCompDef As AssemblyComponentDefinition = aDoc.ComponentDefinition
    oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
    Dim sPartName As String = vbNullString
    Dim sDescription As String = iProperties.Value("Project", "Description")
    Dim sDrawing As String = iProperties.Value("Custom", "DRAWING No.")
    Try
        'CREATE A NEW PART DOCUMENT THAT WILL BE THE SHRINKWRAP SUBSTITUTE
        Dim oPartDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
        Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oDerivedAssemblyDef As DerivedAssemblyDefinition = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(aDoc.FullDocumentName)
        'SET VARIOUS SHRINKWRAP RELATED OPTIONS
        oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
        oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
        oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
        oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
        oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
        Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
        Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)
        Dim oDerivedAss As DerivedAssemblyComponent = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
        Call oDerivedAss.BreakLinkToFile()
        
        'SAVE THE PART
        sPartName = ThisDoc.PathAndFileName(False) & " (SHRINKWRAPPED).ipt"
        ThisApplication.ActiveView.Fit()
        ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute()
        Call oPartDoc.SaveAs(sPartName, False)
    Catch ex As Exception
        MsgBox("Error creating ipt file:" & vblf & ex.message)
    End Try
    
    'Try
        If sPartName = vbNullString Then Exit Sub
        Dim oDoc As Inventor.Document = ThisApplication.Documents.Open(sPartName, True)
        iProperties.Value(sPartName, "Project", "Description") = sDescription
        iProperties.Value(sPartName, "Custom", "DRAWING No.") = sDrawing
        oDoc.Save()
        oDoc.Close()
    'Catch
    'End Try
    
    oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
End Sub
Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods
0 Likes

kwalker1
Enthusiast
Enthusiast

Thanks Mike for the reply.

But unfortunately I am still getting the same error with the code you suggest.

 

The model shrinkwraps correctly and opens but then the error in rule dialogue box appears stating:

 

Error in rule: Shrinkwrap, in document: WW - WALKWAY ASSEMBLY.iam
iProperties:The document named "C:\Inventor Projects\WALKWAYS\WW - WALKWAY ASSEMBLY (SHRINKWRAPPED).ipt" was not found.

 

When I check the shrinkwrap's iproperties, the Description property remains blank and no custom Drawing No. property is created.

 

It seems like the iproperties part of the code is trying to look for an instance of the part file inside the assembly rather than in the project folder.

Do you think this is what's happening?

 

Cheers.

 

Regards,

Kurt.

0 Likes

Owner2229
Advisor
Advisor
Accepted solution

Alright, a little correction. We can't use the full name to update the part's iProperty, but we can use a little more "direct" approach:

 

Sub Main()
    Dim aDoc As Document = ThisApplication.ActiveDocument
    If aDoc.DocumentType <> DocumentTypeEnum.kAssemblyDocumentObject Then Exit Sub 'Assembly documents only
    
    Question = MessageBox.Show("Do you wish to shrinkwrap the Walkway Assembly now for use in the General Arrangement?", "Walkway Assembly",MessageBoxButtons.YesNo)
    If Question <> vbYes Then
        Exit Sub 'Exit
    End If
    
    Dim oAsmCompDef As AssemblyComponentDefinition = aDoc.ComponentDefinition
    oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate
    Dim sPartName As String = vbNullString
    Dim sDescription As String = iProperties.Value("Project", "Description")
    Dim sDrawing As String = iProperties.Value("Custom", "DRAWING No.")
    Try
        'CREATE A NEW PART DOCUMENT THAT WILL BE THE SHRINKWRAP SUBSTITUTE
        Dim oPartDoc As PartDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kPartDocumentObject, , True)
        Dim oPartDef As PartComponentDefinition = oPartDoc.ComponentDefinition
        Dim oDerivedAssemblyDef As DerivedAssemblyDefinition = oPartDef.ReferenceComponents.DerivedAssemblyComponents.CreateDefinition(aDoc.FullDocumentName)
        'SET VARIOUS SHRINKWRAP RELATED OPTIONS
        oDerivedAssemblyDef.DeriveStyle = DerivedComponentStyleEnum.kDeriveAsMultipleBodies
        oDerivedAssemblyDef.IncludeAllTopLevelWorkFeatures = DerivedComponentOptionEnum.kDerivedExcludeAll
        oDerivedAssemblyDef.IncludeAllTopLevelSketches = DerivedComponentOptionEnum.kDerivedExcludeAll
        oDerivedAssemblyDef.IncludeAllTopLeveliMateDefinitions = DerivedComponentOptionEnum.kDerivedExcludeAll
        oDerivedAssemblyDef.IncludeAllTopLevelParameters = DerivedComponentOptionEnum.kDerivedExcludeAll
        Call oDerivedAssemblyDef.SetHolePatchingOptions(DerivedHolePatchEnum.kDerivedPatchNone)
        Call oDerivedAssemblyDef.SetRemoveByVisibilityOptions(DerivedGeometryRemovalEnum.kDerivedRemoveNone)
        Dim oDerivedAss As DerivedAssemblyComponent = oPartDoc.ComponentDefinition.ReferenceComponents.DerivedAssemblyComponents.Add(oDerivedAssemblyDef)
        Call oDerivedAss.BreakLinkToFile()
        
        'SAVE THE PART
        sPartName = ThisDoc.PathAndFileName(False) & " (SHRINKWRAPPED).ipt"
        ThisApplication.ActiveView.Fit()
        ThisApplication.CommandManager.ControlDefinitions.Item("AppIsometricViewCmd").Execute()
        Call oPartDoc.SaveAs(sPartName, False)
    Catch ex As Exception
        MsgBox("Error creating ipt file:" & vblf & ex.message)
    End Try
    
    'Try
        If sPartName = vbNullString Then Exit Sub
        Dim oDoc As Inventor.Document = ThisApplication.Documents.Open(sPartName, True)
        Dim oPropsets As PropertySets = oDoc.PropertySets
Dim oProject As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
Dim oCustom As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
oProject("Description").Expression = sDescription
Dim oDrawing As Inventor.Property
Try
oDrawing = oCustom("DRAWING No.")
Catch
oDrawing = oCustom.Add("", "DRAWING No.")
End Try oDrawing.Expression = sDrawing oDoc.Save() oDoc.Close() 'Catch 'End Try oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("Default").Activate End Sub 

 

Consider using "Accept as Solution" / "Kudos" if you find this helpful.
- - - - - - - - - - - - - - -
Regards,
Mike

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live." - John F. Woods

kwalker1
Enthusiast
Enthusiast

Hi Mike,

The code is working perfectly now.

Together with the code you suggested and referring back to the API Help, you have helped expand my (and hopefully others) iLogics knowledge a little further.

My sincere thanks for your assistance.

 

Cheers.

Kurt.

 

0 Likes

ic198
Advocate
Advocate

Thanks, you solved the problem I was having too 🙂

0 Likes