Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Get iProperties from part in drawing with iLogic and VBA

19 REPLIES 19
Reply
Message 1 of 20
GeorgK
3429 Views, 19 Replies

Get iProperties from part in drawing with iLogic and VBA

Hello together,

 

how could I synchronize my drawing with the referenced part?

 

I have a "User Defined Propertie" called  "RBMATNO" in the part and in the drawing.

 

Thank you very much

 

Georg

 

 

19 REPLIES 19
Message 2 of 20
adam.nagy
in reply to: GeorgK

Hi Georg,

 

You should be able to do something like this - e.g. in VBA:

Sub SynchronizeUserParam()
    Dim dwg As DrawingDocument
    Set dwg = ThisApplication.Documents(2)
    
    Dim part As PartDocument
    Set part = ThisApplication.Documents(1)
    
    Dim param As Variant
    param = dwg.Parameters("RBMATNO").Expression
    
    part.ComponentDefinition.Parameters("RBMATNO").Expression = param
End Sub

Cheers,



Adam Nagy
Autodesk Platform Services
Message 3 of 20
GeorgK
in reply to: adam.nagy

Thank you very much.

Message 4 of 20
adam.nagy
in reply to: GeorgK

oops... not sure know why I thought you said Parameters - which my code was about.

This is how you synchronize an iProperty inside "User Defined Properties"

Sub SynchronizeiProperty()
    Dim dwg As DrawingDocument
    Set dwg = ThisApplication.Documents(1)
    
    Dim part As PartDocument
    Set part = ThisApplication.Documents(2)
    
    ' Accessing "User Defined Properties" set
    Dim dps As PropertySet
    Set dps = dwg.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
    
    Dim pps As PropertySet
    Set pps = part.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
    
    Dim param As Variant
    param = dps("MyProperty").Expression
    
    pps("MyProperty").Expression = param
End Sub


Adam Nagy
Autodesk Platform Services
Message 5 of 20
DuncanAnderson
in reply to: adam.nagy

Adam

 

Will this work in iLogic?

 

If not, can it be done in iLogic?

 

If so, how?

 

Will this work in Inv2015?

 

 

Duncan Anderson

"Humour is one man shouting gibberish in the face of authority, and proving by fabricated insanity that nothing could be as mad as what passes for ordinary living." {Terence 'Spike' Milligan KBE (16 Apr 1918 – 27 Feb 2002)}
Message 6 of 20
adam.nagy
in reply to: DuncanAnderson

Hi,

 

You just have to convert it to iLogic compatible code:

http://adndevblog.typepad.com/manufacturing/2015/11/convert-vba-to-net-ilogic.html

 

Cheers,



Adam Nagy
Autodesk Platform Services
Message 7 of 20
Owner2229
in reply to: DuncanAnderson

Hi, you can use this:

 

oModelRef = ThisDrawing.Document.Sheets.Item(1).DrawingViews.Item(1).ReferencedFile
ModelFileName = oModelRef.FullFileName
oModelDoc = ThisApplication.Documents.Open(ModelFileName, 0)
iProperties.Value("Custom", "RBMATNO") = oModelDoc.PropertySets.Item("User Defined Properties").Item("RBMATNO").Value

 

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
Message 8 of 20
ThomasSwanson
in reply to: GeorgK

Or you could just have Inventor do this for you and not worry with ilogic and VBA.

 

Create the custom Iproperty on the drawing template.  

Then got to Tools --> Document Settings--> Drawing Tab

At the bottom you will see Copy Model iproperty Settings click on that and put a check in the two check boxes.

pic1.jpg

pic2.jpg

Message 9 of 20

I have a multi-sheet drawing, but still need to access Part iProperties
Duncan Anderson

"Humour is one man shouting gibberish in the face of authority, and proving by fabricated insanity that nothing could be as mad as what passes for ordinary living." {Terence 'Spike' Milligan KBE (16 Apr 1918 – 27 Feb 2002)}
Message 10 of 20
adam.nagy
in reply to: DuncanAnderson

As shown in one of the sample codes above, you can find out which document is referenced by a given view on a given sheet.

So you can just iterate through the sheets and the views on them and then access the iproperties of those doucments and then do with them whatever you need to.



Adam Nagy
Autodesk Platform Services
Message 11 of 20
hpmithun
in reply to: adam.nagy

Hi I am trying to do something very similar, We have profile  drawings (sheets for laser cutting) on the 2nd last page (eg 15th sheet) of every drawing set. The page number of the sheet is manually written onto i-properties of each part.

Whenever there is an additional sub assembly added we end up manually changing the  iproperties by incrementing by the additional pages we added. ie if we added 2 pages of subassembly to the drawing sets the new profile page will be moved to sheet 17.  

 

i am stuck where i need to pass the page number to part, i am not getting the right syntax , may be you might be able to help me here.TIA.

regerds

Mithun





Sub Sheet_NO_2_parts()

Dim oSSet As SelectSet

Dim dwodoc As DrawingDocument
Dim tmpsheet As Sheet
Dim PART_NAME As PartDocument
Set PART_NAME = ThisApplication.Documents(2)


Set dwodoc = ThisApplication.ActiveDocument
Set tmpsheet = dwodoc.ActiveSheet
Set oSSet = dwodoc.SelectSet

If oSSet.Count = 0 Then

MsgBox "PLEASE SELECT A VIEW"

Exit Sub
End If


Dim oView As DrawingView
Set oView = oSSet.Item(1)

If oView = kDrawingViewObject Then
Set pps = PART_NAME.PropertySets("{D5CDD505-2E9C-101B-9397-08002B2CF9AE}")
pps("Description").Expression = "Sheet-15"


Else
MsgBox "WORKS ONLY ON DRAWING FILES"

End If
End Sub

Message 12 of 20
dgreatice
in reply to: GeorgK

Hi,

 

this my version.

 

Dim oApp As Application
Dim oDD As DrawingDocument
Dim oSht As Sheet
Dim oDV As DrawingView
Dim oReffDoc As Document
Dim oDwgPropSet As PropertySet
Dim oReffPropSet As PropertySet
Dim oDwgCustProp As Property
Dim oReffCustProp As Property
   
oApp = ThisApplication
oDD = oApp.ActiveDocument
oSht = oDD.ActiveSheet
oDV = oSht.DrawingViews(1)
oReffDoc = oDV.ReferencedDocumentDescriptor.ReferencedDocument
   
oDwgPropSet = oDD.PropertySets("User Defined Properties")
oReffPropSet = oReffDoc.PropertySets("User Defined Properties")
   
oDwgCustProp = oDwgPropSet("RBMATNO")
oReffCustProp = oReffPropSet("RBMATNO")
   
oDwgCustProp.Value = oReffCustProp.Value

Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
Message 13 of 20
Jesper_S
in reply to: GeorgK

Hi.

I have used this iLogic codes.

To get iProperties from model to drawing.

 

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("Project", "Part Number")=iProperties.Value(modelName, "Project", "Part Number")

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

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

And this to send iProperties from the drawing to the model.

 

' 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, "Project", "Part Number")=iProperties.Value("Project", "Part Number")

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

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

iLogicVb.UpdateWhenDone = True

Easy to add or remove iProperties you want to sync.


//Jesper

Did you find this reply helpful ? If so please use the Accept as Solution or Kudos button below.
Message 14 of 20

Hello, How do I run the rule for all drawing views of the sheet. Thanks

Message 15 of 20

@andrescastellanosint Could explain the context of your request? The rule is intended to pick up the first model iproperties and apply to the title block with the same title block in all the drawing sheets. If you want to point to a different view you can use the longer API method shown here 

and change the view number. Common practice is to have view 1 as the model reference.

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 16 of 20

Hello, I am trying to extract information from the title block and add it to the name of the views. This rule only modifies one view for me. 
I would like to be able to make a loop and be able to change the name of all the views.
Message 17 of 20

In this case because the topic is very different I would suggest you to create a new post and check out those sample links.  

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/change-view-label/m-p/10560318#M1279...

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-change-view-label-properties/...

 

https://forums.autodesk.com/t5/inventor-ilogic-and-vb-net-forum/ilogic-code-for-drawing-view-label-c...

If this solved a problem, please click (accept) as solution.‌‌‌‌
Or if this helped you, please, click (like)‌‌
Regards
Alan
Message 18 of 20

HI, thanks for the info, but I really need to get the property "Keywords" of Drawing not the models, and then copy it to the models property of all views. 

Message 19 of 20

Hi @andrescastellanosint,

 

I think this will do what you are asking.

 

I hope this helps.
Best of luck to you in all of your Inventor pursuits,
Curtis
http://inventortrenches.blogspot.com

 

 

oKeywords = iProperties.Value("Summary", "Keywords")

Dim oDoc As DrawingDocument
oDoc = ThisDrawing.Document
Dim oModelDoc As Document

For Each oSheet In oDoc.Sheets
	oSheet.activate
	For Each oView In oSheet.DrawingViews
		oModelDoc = ThisDrawing.ActiveSheet.View(oView.Name).ModelDocument

		oModelDoc.PropertySets.Item(1).Item("Keywords").Value = oKeywords
	Next
Next

 

Message 20 of 20

it was exactly what i needed, Thanks

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report