copy iProperties from one drawing to another

copy iProperties from one drawing to another

mblaptok
Contributor Contributor
1,250 Views
7 Replies
Message 1 of 8

copy iProperties from one drawing to another

mblaptok
Contributor
Contributor

Hi, can sombody help with iLogic rule to copy iProperties from one drawing to another?

 

I have MAIN.DWG with "common" iProperties,  many times, i create new drawing in subfolder let say PART.DWG

Those two (or more) files are not connected, they have different assemblies - but i would like to write iLogic rule in PART.DWG to copy some of iProperties directly from MAIN.DWG - is it possible?

 

Both files are in the same Project.ipj 

0 Likes
Accepted solutions (1)
1,251 Views
7 Replies
Replies (7)
Message 2 of 8

JamieVJohnson2
Collaborator
Collaborator

Possible, certainly. 

  1. Are you coping properties to a file that does not have them even defined, or just copying the values from one document to another that have the defined property, but not the right value? 
  2. Do you know the name of each property,
    1. or is it 'random' and need to copy all properties,
    2. or all properties of a PropertySet (like custom properties only)
    3. or properties with a known keyword.

Open both documents into memory, and start getting properties and values from one placed into another.  Have you attempted to create a rule yet, if so can we see where you are at, if not let us know and we can get you going down the right path.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 3 of 8

mblaptok
Contributor
Contributor

My example files attached

1. property are defined in Drawing1.dwg (no custom)

2. yes i know all of them,  i want to copy to Drawing2.dwg (and many more) those values :

 

iProperties.Value("Project", "Part Number")
iProperties.Value("Project", "Stock Number")
iProperties.Value("Project", "Project")
iProperties.Value("Summary", "Manager")
iProperties.Value("Summary", "Company")
iProperties.Value("Summary", "Title")

 

0 Likes
Message 4 of 8

JamieVJohnson2
Collaborator
Collaborator
Accepted solution

Ok then, you need to open both documents and assign each one a variable, or if you are going to do a batch process, open the base document memorize its values, then open all the batch children to copy too.

dim docBase as inventor.document = thisapplication.documents.open(fullfilepathBase) 

dim docChild as inventor.document = thisapplication.documents.open(fullfilepathChild)

 

Once they are open the rest is pretty simple:

properties are organized into property Sets, and to know which ones you wish to change you can run this probing routine I created:

    Public Sub ReadOutPropertySets(invDoc As Inventor.Document)
        Try
            Dim strPropertySets As String = "Inventor Property Sets" & vbCrLf & "{Property Set Name}" & vbCrLf & "{Property.DisplayName, Property.Name, Property.ID, Property.Type, Property.Expression, Property.Value}"
            For Each pset As PropertySet In invDoc.PropertySets
                strPropertySets += vbCrLf & pset.Name
                For Each prop As [Property] In pset
                    Try
                        strPropertySets += vbCrLf & "      " & prop.DisplayName & ", " & prop.Name & ", " & prop.PropId & ", " & prop.Type & ", " & prop.Expression & ", " & prop.Value
                    Catch ex As Exception
                    End Try
                Next
            Next
            MsgBox(strPropertySets)
        Catch ex As Exception
        End Try
    End Sub

once you have identified the exact property set name and property name (or property id), you can access it with the same features in the above code prop.value = xxx,  and/or variable = prop.value

 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
Message 5 of 8

mblaptok
Contributor
Contributor

Thank You, it works, i need to add :

WriteOutPropertySets

but.... can't this be done easier? i got just a few property to read/set from know one general drawing.

Read/set from model is much more easier.

SyntaxEditor Code Snippet

iProperties.Value("Project", "Part Number") = iProperties.Value("assembly.iam","Project", "Part Number")

I wonder why it can't be like this :

SyntaxEditor Code Snippet

iProperties.Value("assembly1.dwg","Summary", "Manager")= iProperties.Value("assembly2.dwg","Summary", "Manager")

 

SyntaxEditor Code Snippet

Class ThisRule

Shared my_title As String

Sub Main()

Dim docBase As Inventor.Document = ThisApplication.Documents.Open("f:\.......\ProjectName\Drawing1.dwg") 
Dim docChild As Inventor.Document = ThisApplication.Documents.Open("f:\.........\ProjectName\subassembly\Drawing2.dwg")


ReadOutPropertySets(docBase)
WriteOutPropertySets(docChild)

End Sub	


Public Sub ReadOutPropertySets(invDoc As Inventor.Document)
        Try
            Dim strPropertySets As String = "Inventor Property Sets" & vbCrLf & "{Property Set Name}" & vbCrLf & "{Property.DisplayName, Property.Name, Property.ID, Property.Type, Property.Expression, Property.Value}"
            For Each pset As PropertySet In invDoc.PropertySets
                strPropertySets += vbCrLf & pset.Name
                For Each prop As [Property] In pset
                    Try
                        strPropertySets += vbCrLf & "      " & prop.Name & prop.Value
						If prop.Name = "Title" Then my_title = prop.Value
											
                    Catch ex As Exception
                    End Try
                Next
            Next
            'MsgBox(strPropertySets)
        Catch ex As Exception
        End Try
    End Sub
	
	
Public Sub WriteOutPropertySets(invDoc As Inventor.Document)
        Try
            Dim strPropertySets As String = "Inventor Property Sets" & vbCrLf & "{Property Set Name}" & vbCrLf & "{Property.DisplayName, Property.Name, Property.ID, Property.Type, Property.Expression, Property.Value}"
            For Each pset As PropertySet In invDoc.PropertySets
                strPropertySets += vbCrLf & pset.Name
                For Each prop As [Property] In pset
                    Try
                        strPropertySets += vbCrLf & "      " & prop.Name & prop.Value
						If prop.Name = "Title" Then prop.Value=my_title
																		
                    Catch ex As Exception
                    End Try
                Next
            Next
            'MsgBox(strPropertySets)
        Catch ex As Exception
        End Try
    End Sub
	
End Class

 

 

Message 6 of 8

JamieVJohnson2
Collaborator
Collaborator

So now that you know EXACTLY the property set name, and property name you can use some of the built in iLogic property grabbing tools:

  iProperties.Value("Custom", "LoadCG") = strLoadCG

  iProperties.Value("Custom", "PercentDifference") = CStr(Round((Abs(Parameter("TruckReactionLeft") - Parameter("TruckReactionRight")) / iProperties.Mass) * 100, 1)) & "%"

  Dim truckHalf As Double = iProperties.Value("CarWheels", "Custom", "HalfTruckCenter")

 

using iProperties.Value(optional object occurrence exact display name where default is the current document, propertyset name, property name)

to get or set a value.

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 7 of 8

JamieVJohnson2
Collaborator
Collaborator

One clarification:

from: https://help.autodesk.com/view/INVNTOR/2019/ENU/?guid=74dd101d-219e-cba7-e7f7-65ce1d1049f1

componentOrDocNameType: System.Object
The component or document name.

I'm not sure if you can specify a just file name, or if you must specify the full path and file name. 

 

Jamie Johnson : Owner / Sisu Lissom, LLC https://sisulissom.com/
0 Likes
Message 8 of 8

mblaptok
Contributor
Contributor

I have no idea how to use it - post 7.

Post 4 has good solution, Thank You !

0 Likes