macro for copying material

macro for copying material

Anonymous
Not applicable
943 Views
8 Replies
Message 1 of 9

macro for copying material

Anonymous
Not applicable

hi,

 

can someone help me do a macro?

 

i want to pick the part material in my assy and copy it to a the same assy custom prop.

 

many thanks

inventor 2013

vault 2013

0 Likes
Accepted solutions (1)
944 Views
8 Replies
Replies (8)
Message 2 of 9

augusto.goncalves
Alumni
Alumni

I would suggest you start with this blog post: http://modthemachine.typepad.com/my_weblog/2009/03/accessing-assembly-components.html

 

 

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 9

Anonymous
Not applicable

can somebody help me do a simple code to display in msgbox the material of the part ?

 

thanks

0 Likes
Message 4 of 9

jdkriek
Advisor
Advisor

Correct me if I am wrong, you are wanting to be able to click a part inside an Assembly and display the material for that part in a msgbox inside the Assy? And you also want to copy that material to a custom property inside the Assy?

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 5 of 9

Anonymous
Not applicable

yes... thats exactly what i want to do...

 

is it possible?Smiley Frustrated

0 Likes
Message 6 of 9

jdkriek
Advisor
Advisor
Accepted solution

Sure anything is possible 😉

 

I suggest you study the code, it's very simplistic.

 

Public Sub MatCopy()
'JDK 2013
    On Error Resume Next
    
    ' Get the Assy Document
    Dim oAssDoc As AssemblyDocument
    Set oAssDoc = ThisApplication.ActiveDocument
    
    ' Select occurrence
    Dim oOccurrence As ComponentOccurrence
    Set oOccurrence = oAssDoc.SelectSet.Item(1)
        If Err Then
            MsgBox "An occurrence must be selected."
            Err.Clear
            On Error GoTo 0
            Exit Sub
        End If
    
    ' Define name and material as strings
    sName = oOccurrence.name
    sMat = oOccurrence.Definition.Material.name
    
    ' Get custom property set
    Dim customPropSet As PropertySet
    Set customPropSet = oAssDoc.PropertySets( _
    "Inventor User Defined Properties")
    
    ' Add new property with name and material
    Call customPropSet.Add(sMat, sName)
    
    ' Msg the material
    MsgBox (sName & " = " & sMat)
End Sub
Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes
Message 7 of 9

Anonymous
Not applicable

you save my day!!!

 

thank you so so so much..

 

what does this code mean? On Error GoTo 0

what is zero?

 

0 Likes
Message 8 of 9

Anonymous
Not applicable

ive change  sName to some namexxx.

 Call customPropSet.Add(sMat, sName)

 

 

id like to add a code for deleting the namexxx if it exist..

 

thank you so much  Smiley Happy

0 Likes
Message 9 of 9

jdkriek
Advisor
Advisor

On Error GoTo 0 disables any error trapping currently present in the procedure.

Jonathan D. Kriek
MFG Solutions Engineer
KETIV Technologies, Inc.


0 Likes