Chane iProperty of Inserted Part in Drawing File using iLogic.

Chane iProperty of Inserted Part in Drawing File using iLogic.

C_Haines_ENG
Collaborator Collaborator
386 Views
6 Replies
Message 1 of 7

Chane iProperty of Inserted Part in Drawing File using iLogic.

C_Haines_ENG
Collaborator
Collaborator

I would like to be able to setup an iLogic rule that would allow me to change the Description of whatever inserted part I have (Assembly or Part) in the drawing page, 

 

Ideally I could set up a form to have it look like a fillable field, where when the form is closed it will update the models description. 

0 Likes
Accepted solutions (2)
387 Views
6 Replies
Replies (6)
Message 2 of 7

C_Haines_ENG
Collaborator
Collaborator
Accepted solution

For anyone else who has this question, I managed to piece together a bunch of other VBA codes together.

 

'DEFINE MODEL DOCUMENT TO THE CURRENT VIEW INSERTED'
Dim oView As DrawingView
oView = ThisApplication.ActiveDocument.ActiveSheet.DrawingViews(1)
Dim oModelDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

If (oModelDoc Is Nothing) Then Return
	
'LOCATE FILE'
	modelName = IO.Path.GetFileName(oModelDoc.FullFileName)
'SET CURRENT DESCRIPTION'
	CurrentDesc = iProperties.Value(modelName, "Project", "Description")
'INPUT BOX ASKING FOR NEW DESCRIPTION'
	DescFix = InputBox("Prompt", "Title", CurrentDesc)
'CHANGE IPROPERTY OF MODEL AND REFRESH PAGE'
	iProperties.Value(modelName, "Project", "Description") = DescFix
	ThisApplication.ActiveDocument.Update

 

0 Likes
Message 3 of 7

WCrihfield
Mentor
Mentor

Hi @C_Haines_ENG.  Here is a fairly simple example iLogic rule that, when you run it from a drawing, will ask you to select a drawing view, then it will prompt you to enter/edit the value of the view's model document description, while showing you its current value as a suggestion.  You can give this a try if you want.  If this is not exactly what you had in mind, it might at least get you started in the right direction towards creating something better or more specific.

 

If ThisDoc.Document.DocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("A Drawing document must be active for this code to work. Exiting.", vbCritical, "")
	Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDoc.Document
oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Drawing View.")
If IsNothing(oObj) OrElse (TypeOf oObj Is DrawingView = False) Then Exit Sub
Dim oView As DrawingView = oObj
Dim oModel As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
Dim oProjProps As PropertySet = oModel.PropertySets.Item("Design Tracking Properties")
Dim oDescProp As Inventor.Property = oProjProps.Item("Description")
Dim oInputDesc As String = InputBox("Enter/Edit Description", "Model Description", oDescProp.Value)
oDescProp.Value = oInputDesc

 

If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.

If you want and have time, I would appreciate your Vote(s) for My IDEAS :bulb: or you can Explore My CONTRIBUTIONS

 

Edit:  Looks like we both posted a response at the same time, with about the same idea in mind. 😁

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 4 of 7

C_Haines_ENG
Collaborator
Collaborator

Thank you for the help, I posted the code I managed to figure out though!

 

Aswell, my code just retrieves the first model inserted in the page. 

0 Likes
Message 5 of 7

C_Haines_ENG
Collaborator
Collaborator

Would you happen to know how I can state that if there is no Part or assembly in the drawing sheet it will send that error message?

0 Likes
Message 6 of 7

WCrihfield
Mentor
Mentor
Accepted solution

Hi @C_Haines_ENG.  I started from the code you posted, then replaced the 'ActiveDocument' bit with the iLogic shortcut snippet for working with a drawing (ThisDrawing), then used its built-in read-only property called 'ModelDocument', which returns either a generic Document Type object or Nothing.  Then used the old vb.net function 'IsNothing' to check if it returns Nothing.  If so, I use a MsgBox (could also use a MessageBox.Show()), to show the error message, which lets you know, then exits the rule.  But if it did find a model document, the rest of the code runs.  I carried the oDDoc variable down to the last two lines, out of convenience, and am showing a Sheet.Update method there too.  See if this works OK for you.

'DEFINE MODEL DOCUMENT TO THE CURRENT VIEW INSERTED'
oDDoc = ThisDrawing.Document
oModelDoc = ThisDrawing.ModelDocument
If IsNothing(oModelDoc) Then
	MsgBox("No 'Model' document found. Exiting rule.", vbCritical, "No Model")
	Return
End If
'LOCATE FILE'
modelName = IO.Path.GetFileName(oModelDoc.FullFileName)
'SET CURRENT DESCRIPTION'
CurrentDesc = iProperties.Value(modelName, "Project", "Description")
'INPUT BOX ASKING FOR NEW DESCRIPTION'
DescFix = InputBox("Prompt", "Title", CurrentDesc)
'CHANGE IPROPERTY OF MODEL AND REFRESH PAGE'
iProperties.Value(modelName, "Project", "Description") = DescFix
oDDoc.ActiveSheet.Update
oDDoc.Update

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 7

C_Haines_ENG
Collaborator
Collaborator

That works great! I appreciate it. 

0 Likes