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