Copy part of "part name" to "description" iProperties with vba

Copy part of "part name" to "description" iProperties with vba

jorgen_dahlstrom
Participant Participant
1,684 Views
24 Replies
Message 1 of 25

Copy part of "part name" to "description" iProperties with vba

jorgen_dahlstrom
Participant
Participant

Hi

Wondering if someone could help me with this:

 

I want to copy just a part of a part name to description field in iProperties.

ex. I save a part with name: 123A001 Motor Assy for example

After save the part number will be "123A001 Motor Assy" in iProperties

I want to cut "Motor Assy" and paste it to description field as following:

Part Number: 123A001

Description: Motor Assy

 

I manage to copy the whole part name to Description field with following code:

Sub Main()    
    ' Get the active document.
    Dim oDoc As Document
    Set oDoc = ThisApplication.ActiveDocument

    ' Get the PropertySets object.
    Dim oPropSets As PropertySets
    Set oPropSets = oDoc.PropertySets

    ' Get the design tracking property set.
    Dim oPropSet As PropertySet
    Set oPropSet = oPropSets.Item("Design Tracking Properties")

    ' Get the part number iProperty.
    Dim oPartNum_iProp As Property
    Set oPartNum_iProp = oPropSet.Item("Part Number")
   
    ' Get the description iProperty.
    Dim oDesc_iProp As Property
    Set oDesc_iProp = oPropSet.Item("Description")
   
    ' Copy part number to description
    oDesc_iProp.Value = oPartNum_iProp.Value
   
End Sub

 

...but I can't figure out how to cut the describing text.

FYI there is always space between the partnumber and describing text so maybe that can be used as a separator, however it can also be space in the describing text...

 

Any one?

 

/ Jorgen

0 Likes
Accepted solutions (2)
1,685 Views
24 Replies
Replies (24)
Message 21 of 25

ThatWorksForMe
Advocate
Advocate

Use iLogic

- create a new rule with the following content:

Sub Main()
	InventorVb.RunMacro("1", "2", "3")
End Sub

   1, 2 and 3 are mentioned in the screenshot

   in this example the code would be: 

InventorVb.RunMacro("Anwendungsprojekt", "Drucken", "TEST123")

- add a new rule to the action "before save document"

- run the rule

PDM/CAD Administrator
Using Inventor/Vault 2024.3
0 Likes
Message 22 of 25

jorgen_dahlstrom
Participant
Participant

I suck at this!

 

I got error on "No VBA project named "1" was found"...

I belive that 1 should stand for something also 2 & 3

like project name, module name macro name but when I trying to put in the project name I got errors

0 Likes
Message 23 of 25

ThatWorksForMe
Advocate
Advocate

Take a look on the attached file.

PDM/CAD Administrator
Using Inventor/Vault 2024.3
0 Likes
Message 24 of 25

jorgen_dahlstrom
Participant
Participant

Now it works..

 

Thanks

/ Jorgen

0 Likes
Message 25 of 25

ThatWorksForMe
Advocate
Advocate

Perfect

PDM/CAD Administrator
Using Inventor/Vault 2024.3
0 Likes