Changing Description Field in VBA

Changing Description Field in VBA

Anonymous
Not applicable
824 Views
6 Replies
Message 1 of 7

Changing Description Field in VBA

Anonymous
Not applicable
How do I set the value of a description through VBA? I believe it has something to do with the PropertiesForDesignTrackingProperties.kDescriptionDesignTrackingProperties, but I'm not sure how to set this to a string. Any ideas?


Thanks,

Mike
0 Likes
825 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable
This VBA macro will prompt and set the
description.

 

Public Sub Set_Description()
   

    NewDescription = InputBox("Enter new description:", "New
Description")

 

   
ThisApplication.ActiveDocument.PropertySets("{32853F0F-3444-11d1-9E93-0060B03C1CA6}").ItemByPropId(kDescriptionDesignTrackingProperties).Value
= NewDescription

 

End Sub


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
How
do I set the value of a description through VBA? I believe it has something to
do with the
PropertiesForDesignTrackingProperties.kDescriptionDesignTrackingProperties,
but I'm not sure how to set this to a string. Any ideas?


Thanks,

Mike

0 Likes
Message 3 of 7

Anonymous
Not applicable
Thank you very much. That worked perfectly. Where did you find how to do this?

Thanks again,

Mike
0 Likes
Message 4 of 7

Anonymous
Not applicable
I participated in a API course half a year ago to
get the basic knowledge about the possibilities, but a good place to look is in
the samples and by using the Object Browser (shortcut in VB/VBA editor press F2)
you can find all the details about the Inventor API, you just have to get
used to use the Object Browser just like the Design Asist./Manager
:)


style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Thank
you very much. That worked perfectly. Where did you find how to do this?

Thanks again,

Mike

0 Likes
Message 5 of 7

Anonymous
Not applicable
Thanks for the quick response. I've got one more question... Can you tell me how to read in data from the comment field of a parameter (into VBA)?

Thanks,

Mike
0 Likes
Message 6 of 7

Anonymous
Not applicable
In the sample list find the example
"Model Parameters
Example"


title="Model Parameters Example">
 


size=2>I've just added one line to get the comment too (look for the green
comment in the code below) 


size=2>
 


size=2>In the VBA editor press Ctrl-G to enable the Immediate (debug)
window this will show all the information about all parameters when the code has
been running.

 

Public Sub ModelParameters()
' Obtain the active document, this assumes
' that a part document is active in Inventor.
Dim oPartDoc As Inventor.PartDocument
Set oPartDoc = ThisApplication.ActiveDocument

' Obtain the Parameters collection
Dim oParams As Parameters
Set oParams = oPartDoc.ComponentDefinition.Parameters

' Iterate through the Parameters collection to obtain
' information about the Parameters
Dim iNumParams As Long
Debug.Print "ALL PARAMETERS"
For iNumParams = 1 To oParams.Count
'Display the Name
Debug.Print " Name: " & oParams.Item(iNumParams).Name

'Display the Parameter Type
Select Case oParams.Item(iNumParams).Type
Case kModelParameterObject
Debug.Print " Type: " & "Model Parameter"
Case kTableParameterObject
Debug.Print " Type: " & "Table Parameter"
Case kUserParameterObject
Debug.Print " Type: " & "User Parameter"
End Select

'Display the Value
Debug.Print " Value: " & oParams.Item(iNumParams).Value
        'Display the Comment
        Debug.Print "  Comment: " & oParams.Item(iNumParams).Comment

'Display the Health Status
Select Case oParams.Item(iNumParams).HealthStatus
Case kDeletedHealth
Debug.Print " Health Status: " & "Deleted"
Case kDriverLostHealth
Debug.Print " Health Status: " & "Driver Lost"
Case kInErrorHealth
Debug.Print " Health Status: " & "In Error"
Case kOutOfDateHealth
Debug.Print " Health Status: " & "Out of Date"
Case kUnknownHealth
Debug.Print " Health Status: " & "Unknown"
Case kUpToDateHealth
Debug.Print " Health Status: " & "Up to Date"
End Select
Next iNumParams

' Obtain the Model Parameterx collection
Dim oModelParams As ModelParameters
Set oModelParams = oParams.ModelParameters

' Iterate through the Model Parameters collection
Dim iNumModelParams As Long
Debug.Print "MODEL PARAMETER VALUES"
For iNumModelParams = 1 To oModelParams.Count
' Display the Name
Debug.Print " Name:" & oModelParams.Item(iNumModelParams).Name

' Display the Value
Debug.Print " Value: " & oModelParams.Item(iNumModelParams).Value

' Display the units
Debug.Print " Units: " & oModelParams.Item(iNumModelParams).Units

' Change the Model Parameter values
oModelParams.Item(iNumModelParams).Value = oModelParams.Item(iNumModelParams).Value * 2
Next iNumModelParams

' Accessing a particular parameter if you know its name, the user and reference parameters can also be accessed in a similar way
oModelParams.Item("d0").Name = "NewParam"

' Change the value of the newly named parameter "param1"
oModelParams.Item("NewParam").Value = 25

' Update the model.
oPartDoc.Update
End Sub



style="PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
Thanks
for the quick response. I've got one more question... Can you tell me how to
read in data from the comment field of a parameter (into VBA)?

Thanks,

Mike

0 Likes
Message 7 of 7

Anonymous
Not applicable
The above macro worked great for a part file, however, when a part file is being edited in an assembly, the description is saved in the parent Assembly file (not in the part file). How do I change the description in the part file when it is being edited within an assembly? ____________ I beleive the problem is ThisApplication.ActiveDocument... refers to the parent assembly and not the edited file. Please help???
0 Likes