iLogic Help - Code for taking ipt iProperties to IDW iproperties

iLogic Help - Code for taking ipt iProperties to IDW iproperties

simon4D86F
Enthusiast Enthusiast
2,502 Views
12 Replies
Message 1 of 13

iLogic Help - Code for taking ipt iProperties to IDW iproperties

simon4D86F
Enthusiast
Enthusiast

Hello Everyone,

 

I have been trying for some time and failed.

 

I would like a piece of code that I can use in my drawings template that will copy the iProperties from within the IPT or IAM that is placed on the drawing and place the copied iproperties within the iproperties of the IDW.

 

The main reason for doing this, or at least trying is so that when I place IDW's into the vault, the iproperties fields are not left blank.

Creating forms within ipt's and iam's is no problem, I can and have done that, but when it comes to VB Code, lets be honest, I am crap and just cannot get my head around the language.

 

Can anyone help?

 

Many thanks

 

0 Likes
Accepted solutions (2)
2,503 Views
12 Replies
Replies (12)
Message 2 of 13

Sergio.D.Suárez
Mentor
Mentor

Hi, Here is an example in ilogic, I put the fragment to select the view because sometimes you have views of different parts and you may want to transfer only the properties of a part to the drawing file.

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oView As DrawingView

oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
If oView Is Nothing Then Exit Sub

oModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

'Get the properties of the reference model of the view
oPartNumProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value  
oReviNumProp = oModelDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value  
oDescripProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value  
oStocNumProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value  

'Transfer the properties to the drawing file
oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = oPartNumProp
oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value = oReviNumProp
oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = oDescripProp
oDoc.PropertySets.Item("Design Tracking Properties").Item("Stock Number").Value = oStocNumProp

 Here you have more descriptions of how to access the properties, you have to write the names well, if you do not do it, you will return an error.

 

https://modthemachine.typepad.com/my_weblog/2010/02/accessing-iproperties.html
I hope I was clear. regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 3 of 13

simon4D86F
Enthusiast
Enthusiast

Hi @Sergio.D.Suárez ,

Many thanks for the code, I tried it and it works fine, that is until I try to make a few changes so that the info within the part that I need, comes over to the IDW.  

 

I have......

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oView As DrawingView

oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
If oView Is Nothing Then Exit Sub

oModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

'Get the properties of the reference model of the view
oPartNumProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value  
oReviNumProp = oModelDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value  
oDescripProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value  
oDescripProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value  
oStocNumProp = oModelDoc.PropertySets.Item("Inventor Document Summary Information").Item("Company").Value  
oStocNumProp = oModelDoc.PropertySets.Item("Inventor Document Summary Information").Item("Keywords").Value 

'Transfer the properties to the drawing file
oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = oPartNumProp
oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value = oReviNumProp
oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = oDescripProp
oDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value = oProjProp
oDoc.PropertySets.Item("Inventor Document Summary Information").Item("Company").Value = oCompanyProp
oDoc.PropertySets.Item("Inventor Document Summary Information").Item("Keywords").Value = oKeywordsProp

 

and the Error message I get is....

 

"Error in rule: iProperties to Drawing, in document: XXX-XXX-XXXX-001.idw

Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))"

 

Can you tell me what I am doing wrong please

 

Many thanks

0 Likes
Message 4 of 13

Anonymous
Not applicable

I was able to figure out that the line giving problems is:

 

oStocNumProp = oModelDoc.PropertySets.Item("Inventor Document Summary Information").Item("Keywords").Value

 

But I don't know enough about code yet to tell you why. 

0 Likes
Message 5 of 13

Sergio.D.Suárez
Mentor
Mentor

try this line of code

 

oStocNumProp = oModelDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value

Best Regards!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 6 of 13

Sergio.D.Suárez
Mentor
Mentor

try this line of code

 

Dim oDoc As DrawingDocument = ThisDoc.Document
Dim oView As DrawingView

oView = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select View")
If oView Is Nothing Then Exit Sub

oModelDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument

'Get the properties of the reference model of the view
oPartNumProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value  
oReviNumProp = oModelDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value  
oDescripProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value  
oDescripProp = oModelDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value  
oStocNumProp = oModelDoc.PropertySets.Item("Inventor Document Summary Information").Item("Company").Value  
oStocNumProp = oModelDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value .Value 

'Transfer the properties to the drawing file
oDoc.PropertySets.Item("Design Tracking Properties").Item("Part Number").Value = oPartNumProp
oDoc.PropertySets.Item("Inventor Summary Information").Item("Revision Number").Value = oReviNumProp
oDoc.PropertySets.Item("Design Tracking Properties").Item("Description").Value = oDescripProp
oDoc.PropertySets.Item("Design Tracking Properties").Item("Project").Value = oProjProp
oDoc.PropertySets.Item("Inventor Document Summary Information").Item("Company").Value = oCompanyProp
oDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value = oKeywordsProp

 Best Regards!


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 7 of 13

simon4D86F
Enthusiast
Enthusiast

Hi,

 

Thanks for the reply and help.

 

I have tried the code and it is working in a manner.  It copies the Revision over and the Project name, however, the project name ends up in the Description column.

 

I also removed a .Value from this line after I still get the error message, Did I do right by removing it?

 

oStocNumProp = oModelDoc.PropertySets.Item("Inventor Summary Information").Item("Keywords").Value .Value 

 

I did try the code with and without the extra .Value, and still get the same error message....

 

"Error in rule: iProperties To Drawing, in document: XXX-XXX-XXX-XXX-004.idw

The parameter is incorrect. (Exception from HRESULT: 0x80070057 (E_INVALIDARG))"

 

I know you mentioned that you hadn't figured out the error, but I will gladly admit, this is above my capabilities.....

 

 

Message 8 of 13

Sergio.D.Suárez
Mentor
Mentor

JajaSmiley Frustrated. I'm sorry. Delete the duplicate string ".value" . Must be unique string. Regards


Please accept as solution and give likes if applicable.

I am attaching my Upwork profile for specific queries.

Sergio Daniel Suarez
Mechanical Designer

| Upwork Profile | LinkedIn

0 Likes
Message 9 of 13

simon4D86F
Enthusiast
Enthusiast

Hi Sergio,

 

I have removed the extra .value.

 

I still get the same results, Projects goes to Description and nothing else happens plus I still get the error message.

 

I have tried rewriting it in the manner that you have suggested and have also tried rewriting it using the info from the site you recommended, however, I just end up getting error messages or the code throws a fit and will not even run.

0 Likes
Message 10 of 13

Jesper_S
Collaborator
Collaborator
Accepted solution

Hi.

 

I have used this in the past. Don't know if it will work.

If (ThisDrawing.ModelDocument Is Nothing) Then Return

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

'read the values from the Custom iProperties in the part file

'and apply them to the Custom iProperties with the same name in the drawing

iProperties.Value("Custom", "Header 1") = iProperties.Value(modelName, "Custom", "Header 1")

iProperties.Value("Custom", "Header 2") = iProperties.Value(modelName, "Custom", "Header 2")

iProperties.Value("Custom", "Header 3") = iProperties.Value(modelName, "Custom", "Header 3")

iProperties.Value("Custom", "Remarks") = iProperties.Value(modelName, "Custom", "Remarks")

iProperties.Value("Project", "Part Number")=iProperties.Value(modelName, "Project", "Part Number")

iProperties.Value("Summary", "Company")=iProperties.Value(modelName, "Summary", "Company")

iProperties.Value("Project", "Project")=iProperties.Value(modelName, "Project", "Project")

iProperties.Value("Summary", "Title")=iProperties.Value(modelName, "Summary", "Title")

'iProperties.Value(modelName, "Project", "Revision Number") = iProperties.Value("Project", "Revision Number")

iProperties.Value("Custom", "Header 3") = iProperties.Value("Summary", "Title")

'iProperties.Value("Custom", "Mass") = iProperties.Value(modelName, "Custom", "Mass")

 

 

And then I have used this to push iProperties from the drawing back to the 3D model.

If (ThisDrawing.ModelDocument Is Nothing) Then Return

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

'read the values from the Custom iProperties in the part file

'and apply them to the Custom iProperties with the same name in the drawing

iProperties.Value("Custom", "Header 1") = iProperties.Value(modelName, "Custom", "Header 1")

iProperties.Value("Custom", "Header 2") = iProperties.Value(modelName, "Custom", "Header 2")

iProperties.Value("Custom", "Header 3") = iProperties.Value(modelName, "Custom", "Header 3")

iProperties.Value("Custom", "Remarks") = iProperties.Value(modelName, "Custom", "Remarks")

iProperties.Value("Project", "Part Number")=iProperties.Value(modelName, "Project", "Part Number")

iProperties.Value("Summary", "Company")=iProperties.Value(modelName, "Summary", "Company")

iProperties.Value("Project", "Project")=iProperties.Value(modelName, "Project", "Project")

iProperties.Value("Summary", "Title")=iProperties.Value(modelName, "Summary", "Title")

'iProperties.Value(modelName, "Project", "Revision Number") = iProperties.Value("Project", "Revision Number")

iProperties.Value("Custom", "Header 3") = iProperties.Value("Summary", "Title")

'iProperties.Value("Custom", "Mass") = iProperties.Value(modelName, "Custom", "Mass")

Then I don't have to go back to the 3D to update the properties.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes
Message 11 of 13

simon4D86F
Enthusiast
Enthusiast

Hi Jesper_s,

 

Many thanks, I will give this a try and get back to you

0 Likes
Message 12 of 13

simon4D86F
Enthusiast
Enthusiast
Accepted solution

Hi Jesper_s,

 

Many many thanks, the code surprised me a little, I could actually follow it, understand it and of course make the required changes to it.

 

Fantastic result. Smiley Very HappySmiley Very HappySmiley Very Happy

 

My changes where as follows...

 

If (ThisDrawing.ModelDocument Is Nothing) Then Return

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

'read the values from the Custom iProperties in the part file

'and apply them to the Custom iProperties with the same name in the drawing

iProperties.Value("Summary", "Company") = iProperties.Value(modelName, "Summary", "Company")
iProperties.Value("Summary", "Keywords") = iProperties.Value(modelName, "Summary", "Keywords")
iProperties.Value("Summary", "Title")=iProperties.Value(modelName, "Summary","Title")
iProperties.Value("Project", "Description") = iProperties.Value(modelName, "Project", "Description")
iProperties.Value("Project", "Project")=iProperties.Value(modelName, "Project", "Project")
iProperties.Value("Summary", "Category")=iProperties.Value(modelName, "Summary", "Category")
0 Likes
Message 13 of 13

Jesper_S
Collaborator
Collaborator

Glad to help.

But I see that I sent the wrong iLogic for the second to send iProperties from the drawing to the 3D.

 

' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet

'Get the name Of the first model in the drawing
modelName = IO.Path.GetFileName(ThisDrawing.ModelDocument.FullFileName)

iProperties.Value(modelName, "Custom", "Header 1") = iProperties.Value("Custom", "Header 1")

iProperties.Value(modelName, "Custom", "Header 2") = iProperties.Value("Custom", "Header 2")

iProperties.Value(modelName, "Custom", "Header 3") = iProperties.Value("Custom", "Header 3")

'iProperties.Value(modelName, "Custom", "Remarks") = iProperties.Value("Custom", "Remarks")

iProperties.Value(modelName, "Project", "Part Number")=iProperties.Value("Project", "Part Number")

iProperties.Value(modelName, "Summary", "Company")=iProperties.Value("Summary", "Company")

iProperties.Value(modelName, "Project", "Project")=iProperties.Value("Project", "Project")

iProperties.Value(modelName, "Summary", "Title")=iProperties.Value("Summary", "Title")

iLogicVb.UpdateWhenDone = True

//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
0 Likes