ipn custom iproperty to iam

ipn custom iproperty to iam

JamieSENG
Advocate Advocate
730 Views
5 Replies
Message 1 of 6

ipn custom iproperty to iam

JamieSENG
Advocate
Advocate

Hello,

 

I have a dwg title block set up so that when saved it takes the sheet size of the drawing and creates a custom property in the iam/ipt.

 

My issue is that fitted assembly models are exploded to create their drawing so it's the ipn file that takes the property.

 

Is there a way to have that property copy over?

 

Thanks in advance.

0 Likes
731 Views
5 Replies
Replies (5)
Message 2 of 6

Owner2229
Advisor
Advisor

Hey, you can try something like this:

It's VB.Net, so it might need some tweaks for iLogic.

 

Sub WriteMyProperties()
	oDoc As Inventor.Document = ThisApplication.ActiveDocument 'Get current document
	Dim oPresent As Inventor.Document = oDoc.ReferencedDocuments.Item(1) 'Get first inserted doc
	Dim oModel As Inventor.Document = oPresent.ReferencedDocuments.Item(1) 'Get first sub doc
	iProperty(oModel, "PartNumber").Expression = "PartNumber" 'Write to Project iProperty
	iPropertyUser(oModel, "MyCustomProperty").Expression = "Whatever" 'Write to Custom iProperty
End Sub

Public Function iProperty(oDoc As Inventor.Document, oProp As String) As Inventor.Property
	Dim oPropsets As PropertySets = oDoc.PropertySets
	Dim oPropSet As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
	Try
		iProperty = oPropSet.Item(oProp)
	Catch
		oPropSet.Add("", oProp)
		iProperty = oPropSet.Item(oProp)
	End Try
	oPropsets = Nothing
	oPropSet = Nothing
End Function
	
Public Function iPropertyUser(oDoc As Inventor.Document, oProp As String) As Inventor.Property
	Dim oPropsets As PropertySets = oDoc.PropertySets
	Dim oPropSet As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
	Try
		iPropertyUser = oPropSet.Item(oProp)
	Catch
		oPropSet.Add("", oProp)
		iPropertyUser = oPropSet.Item(oProp)
	End Try
	oPropsets = Nothing
	oPropSet = Nothing
End Function

 

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
Message 3 of 6

JamieSENG
Advocate
Advocate

Thanks for the reply,

 

I'm not familiar with VB so wouldn't even know where to start.

 

What's this code actually doing? I see reference to a drawing, Is that right?

0 Likes
Message 4 of 6

Owner2229
Advisor
Advisor

Hi, the code is to be runned in a drawing. It will write to the part/assembly document placed in the drawing.

To use it as iLogic rule just change:

Sub WriteMyProperties()

To

Sub Main()

 And you're good to go. It might throw some errors, but it will basically tell you what needs to be corrected.

 

To write to custom iProperty in the placed part/assembly, you can use this line:

iPropertyUser(oModel, "MyCustomPropertyName").Expression = "what you want to write there"

 So let's say I want to read an iProperty named "Hedgehog" from the drawing to part's iProperty named "Fish":

Sub Main()
	oDoc As Inventor.Document = ThisApplication.ActiveDocument 'Get current document
	Dim oPresent As Inventor.Document = oDoc.ReferencedDocuments.Item(1) 'Get first inserted doc
	Dim oModel As Inventor.Document = oPresent.ReferencedDocuments.Item(1) 'Get first sub doc
	Dim aValue As String = iPropertyUser(oDoc, "Hedgehog").Expression 'Read from drawing
	iPropertyUser(oModel, "Fish").Expression = aValue 'Write to part
End Sub

Public Function iProperty(oDoc As Inventor.Document, oProp As String) As Inventor.Property
	Dim oPropsets As PropertySets = oDoc.PropertySets
	Dim oPropSet As PropertySet = oPropsets.Item("{32853F0F-3444-11D1-9E93-0060B03C1CA6}")
	Try
		iProperty = oPropSet.Item(oProp)
	Catch
		oPropSet.Add("", oProp)
		iProperty = oPropSet.Item(oProp)
	End Try
	oPropsets = Nothing
	oPropSet = Nothing
End Function
	
Public Function iPropertyUser(oDoc As Inventor.Document, oProp As String) As Inventor.Property
	Dim oPropsets As PropertySets = oDoc.PropertySets
	Dim oPropSet As PropertySet = oPropsets.Item("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
	Try
		iPropertyUser = oPropSet.Item(oProp)
	Catch
		oPropSet.Add("", oProp)
		iPropertyUser = oPropSet.Item(oProp)
	End Try
	oPropsets = Nothing
	oPropSet = Nothing
End Function
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
Message 5 of 6

JamieSENG
Advocate
Advocate

I've probably not been as clear as I should have been. I'll go through the process again to give a better understanding of my issue's.

 

I've just created my Fitted Assembly. Now I need to explode it to use that then .ipn file for the purpose of an exploded view drawing.

 

The dwg has a rule that runs on save and takes the value of the sheet i.e. A3, A2 etc... And creates the custom iproperty, iProperties.Value(modelName, "Custom", "Paper Size") =size

Now there’s no issue when the drawing view is of an .iam, but as it's the .ipn drawing I need it's there my problem begins.

 

To my knowledge, the .ipn file and .iam file aren’t linked other than the reference to the .iam in the presentations modal space. In the drawing, I see the .iam is referenced in the .ipn but that’s because the part list is made up from the .iam file has is the title block, Confusing.

 

I don’t see how I can change my code because I can’t reference my model through its parts list and I can’t tell my .ipn to send its custom property to its parent because there’s no ilogic in ipn’s. Without adding the .iam to the drawing I'm stuck. I did have a thought however of if it's possible to populate the .ipn file with the properties of the parent .iam? I figure that if it was then I could look to use a code that checks at the same time for a custom iproperty, if yes catch value of some sort.

0 Likes
Message 6 of 6

JamieSENG
Advocate
Advocate
'reads sheet size from the Title Block
'and saves it in the custom iProperty

'active sheet
Dim oSheet As Sheet = ActiveSheet.Sheet
'reference to the existing title block
Dim oTitleBlock As TitleBlock = oSheet.TitleBlock
' Obtain a reference to the title block defintion.
Dim oDef As TitleBlockDefinition = oTitleBlock.Definition
'this sketch contains the collection of all text boxes of the title block
Dim oSketch As DrawingSketch = oDef.Sketch
'reference to the text box that stores Sheet Size string
'in this template it is the 27th text box in the collection
Dim oBox As TextBox = oSketch.TextBoxes.Item(27)
'read the sheet size
Dim size As String  = oTitleBlock.GetResultText(oBox)

modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

iProperties.Value(modelName, "Custom", "Paper Size") =size
'Forces update after rule runs 
iLogicVb.UpdateWhenDone = True

This is the ilogic used in the dwg template 

0 Likes