iLogic check iProp from idw, open file and popup box for input

iLogic check iProp from idw, open file and popup box for input

Anonymous
Not applicable
1,465 Views
14 Replies
Message 1 of 15

iLogic check iProp from idw, open file and popup box for input

Anonymous
Not applicable

Hi all, i've made an ilogic macro to check the part or assembly description when i made a drawing.

It's triggered when i save.

 

This is the macro

 

' Get drawing path
modelFullFileName = ThisDrawing.ModelDocument.FullFileName
Dim oPart As PartDocument
Dim oPartPath As String
Dim sDesc As String        'Variable for Description iProperty
sDesc = iProperties.Value("Project", "Description")


If sDesc = "" Then
	
MsgBox("DESCRIZIONE MANCANTE")

' Open the target part
ThisApplication.Documents.Open(modelFullFileName)

iLogicVb.RunExternalRule("REGOLA_DESC")

End If

 

and when it work,at the end open another rule (because in the same rule the input box didn't work for me)

 

InventorVb.DocumentUpdate()

Dim sDesc As String        'Variable for Description iProperty
sDesc = iProperties.Value("Project", "Description")

If sDesc = "" Then
    myparam = InputBox("The Description iProperty is empty" & vbLf & "Please Fill in the File Description", "Missing Description", "")
     iProperties.Value("Project", "Description") = myparam
     InventorVb.DocumentUpdate()
     ThisDoc.Save
End If

opendoc = ThisDoc.PathAndFileName()'saves doc path and file name
doc = ThisApplication.Documents.Open(opendoc & ".ipt")'saves 'doc' as the open application from 'opendoc' adding the extension '.iam'
doc.Close 'closes the indicated document 'doc'

 

But if i do all from the first macro, when i write some in the input box and press enter going in error.

 

But if i run only the second macro , it work.

 

Someone know why in the first example it doesn't work?

Thank you

0 Likes
Accepted solutions (1)
1,466 Views
14 Replies
Replies (14)
Message 2 of 15

WCrihfield
Mentor
Mentor

Here is the code from one of the external iLogic rules I have used in the past, that is to be initiated from the active drawing document, and compares the Title and Description iProperty values from both the Drawing and the Model files, and if there is any differences, it notifies you and asks you what you want to do about it.

And there are 3 pre-defined options to choose from.

  •  Copy the value from the drawing back to the model
  • Copy the value from the model to the drawing
  • Or do nothing (in-case you might want to leave it that way, for some reason.

I think your problems may be stemming from how you are retrieving the iProperty values.  Any time you use iProperty.Value(oPropertySet, oProperty) you are getting that property from the active document (the document that was active when you started the rule).  There is an alternative way of using that line to retrieve iProperty values from components within an active assembly, by including the component as the first of three input variables within the (), but in general, when you want to access the iProperties of other documents, you should always go through the oOtherDoc.PropertySets.PropertySet.Property.Value = .

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MessageBox.Show("The Rule named '" & iLogicVb.RuleName & "' attempted to run." & vbCrLf &
	"However, it was terminated because the 'Active Document' is the wrong type fot it to work with." & vbCrLf &
	"It only works for DRAWING DOCUMENTS.", "WRONG DOCUMENT TYPE",MessageBoxButtons.OK, MessageBoxIcon.Error)
	Return
End If

Dim oMDoc As Document = ThisDrawing.ModelDocument
If oMDoc Is Nothing Then
	Return
End If

Dim oDtoM As String = "COPY IT FROM DRAWING TO MODEL"
Dim oMtoD As String = "COPY IT FROM MODEL TO DRAWING"
Dim oDN As String = "DO NOTHING"

Dim oWhatToDo As New ArrayList
oWhatToDo.Add(oDtoM)
oWhatToDo.Add(oMtoD)
oWhatToDo.Add(oDN)

Dim oPropSets As PropertySets = oMDoc.PropertySets

'[ Compare Titles
Dim oInvSumInfo As PropertySet = oPropSets.Item("Inventor Summary Information")
Dim oModelTitle As String = oInvSumInfo.Item("Title").Value.ToString
Dim oDrawingTitle As String = iProperties.Value("Summary", "Title").ToString

If oModelTitle = oDrawingTitle Then
	GoTo Description
ElseIf oModelTitle <> oDrawingTitle Then
	oTitleAns = InputListBox("This Drawing's 'Title' doesn't match the referenced Model File's 'Title'." & vbNewLine & 
	"What do you want to do? ", oWhatToDo, oWhatToDo.Item(1), "TITLES DON'T MATCH", "OPTIONS")
	If oTitleAns = "" Then
		GoTo Description
	ElseIf oTitleAns = oDtoM Then
		oModelTitle = oDrawingTitle
		oMDoc.Save
	ElseIf oTitleAns = oMtoD Then
		oDrawingTitle = oModelTitle
	ElseIf oTitleAns = oDN Then
		GoTo Description
	End If
End If
']
Description :
'[ Compare Descriptions
Dim oDesTracProps As PropertySet = oPropSets.Item("Design Tracking Properties")
Dim oModelDesc As String = oInvSumInfo.Item("Description").Value.ToString
Dim oDrawingDesc As String = iProperties.Value("Project", "Description").ToString

If oModelDesc = oDrawingDesc Then
	Return
ElseIf oModelDesc <> oDrawingDesc Then
	oDescAns = InputListBox("This Drawing's 'Description' doesn't match the referenced Model File's 'Description'." & vbNewLine & 
	"What do you want to do?", oWhatToDo, oWhatToDo.Item(1), Title := "DESCRIPTIONS DON'T MATCH", ListName := "OPTIONS")
	If oDescAns = "" Then
		Return
	ElseIf oDescAns = oDtoM Then
		oModelDesc = oDrawingDesc
		oMDoc.Save
	ElseIf oDescAns = oMtoD Then
		oDrawingDesc = oModelDesc
	ElseIf oDescAns = oDN Then
		Return
	End If
End If
']

InventorVb.DocumentUpdate()

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 15

Anonymous
Not applicable

Yes, the problem is getting that property from the active document and i use

InventorVb.DocumentUpdate()

 

to "update" the document info, but it don't work.

 

I try your macro now

0 Likes
Message 4 of 15

Anonymous
Not applicable
 

Inventor_FedRfU6fRn.png

Error for me

0 Likes
Message 5 of 15

WCrihfield
Mentor
Mentor

Everyone's system & settings are different, so changed a few little things within the code that may help.

See if this variation works better for you.  And if it doesn't, could you please include the screen shot of both tabs within the error message?  Often the second tab (more info) is more informational and may help me better understand the error.

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule only works when started from a drawing document. Exiting.",vbOKOnly + vbExclamation,"WRONG DOCUMENT TYPE")
	Return
End If

If ThisDrawing.ModelDocument Is Nothing Then
	MsgBox("No Model Document was found for the active drawing. Exiting.",vbOKOnly + vbExclamation,"NO MODEL")
	Return
End If

Dim oMDoc As Document = ThisDrawing.ModelDocument

Dim oDtoM As String = "COPY IT FROM DRAWING TO MODEL"
Dim oMtoD As String = "COPY IT FROM MODEL TO DRAWING"
Dim oDN As String = "DO NOTHING"

Dim oWhatToDo As New ArrayList
oWhatToDo.Add(oDtoM)
oWhatToDo.Add(oMtoD)
oWhatToDo.Add(oDN)

Dim oPropSets As PropertySets = oMDoc.PropertySets


Dim oInvSumInfo As PropertySet = oPropSets.Item("Inventor Summary Information")
Dim oModelTitle As String = oInvSumInfo.Item("Title").Value.ToString
Dim oDrawingTitle As String = iProperties.Value("Summary", "Title").ToString

If oModelTitle = oDrawingTitle Then
	GoTo Description
ElseIf oModelTitle <> oDrawingTitle Then
	oTitleAns = InputListBox("This Drawing's 'Title' doesn't match the referenced Model File's 'Title'." & vbCrLf & 
	"What do you want to do? ", oWhatToDo, oWhatToDo.Item(1), "TITLES DON'T MATCH", "OPTIONS")
	If oTitleAns = "" Then
		GoTo Description
	ElseIf oTitleAns = oDtoM Then
		oModelTitle = oDrawingTitle
		oMDoc.Save
	ElseIf oTitleAns = oMtoD Then
		oDrawingTitle = oModelTitle
	ElseIf oTitleAns = oDN Then
		GoTo Description
	End If
End If


Description :

Dim oDesTracProps As PropertySet = oPropSets.Item("Design Tracking Properties")
Dim oModelDesc As String = oInvSumInfo.Item("Description").Value.ToString
Dim oDrawingDesc As String = iProperties.Value("Project", "Description").ToString

If oModelDesc = oDrawingDesc Then
	Return
ElseIf oModelDesc <> oDrawingDesc Then
	oDescAns = InputListBox("This Drawing's 'Description' doesn't match the referenced Model File's 'Description'." & vbCrLf & 
	"What do you want to do?", oWhatToDo, oWhatToDo.Item(1), "DESCRIPTIONS DON'T MATCH", "OPTIONS")
	If oDescAns = "" Then
		Return
	ElseIf oDescAns = oDtoM Then
		oModelDesc = oDrawingDesc
		oMDoc.Save
	ElseIf oDescAns = oMtoD Then
		oDrawingDesc = oModelDesc
	ElseIf oDescAns = oDN Then
		Return
	End If
End If

InventorVb.DocumentUpdate()

Also, make sure that within the Options tab for that iLogic rule in the Rule Editor, the "Straight VB code" is not checked, and that the "Silent operation" option is checked.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 6 of 15

WCrihfield
Mentor
Mentor

Also, it appears that your error message is in Italian.  So if your Inventor and iLogic Rule Editor is also set to use Italian language within, you may have to translate some of it before you can use it.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 15

Anonymous
Not applicable

Inventor_wGNj2eOdkI.png

This is error from your second macro

0 Likes
Message 8 of 15

Anonymous
Not applicable

@WCrihfield wrote:

Also, it appears that your error message is in Italian.  So if your Inventor and iLogic Rule Editor is also set to use Italian language within, you may have to translate some of it before you can use it.


Anh ok, i try

0 Likes
Message 9 of 15

WCrihfield
Mentor
Mentor

OK. It was having problems finding the Property.

Try this:

 

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule only works when started from a drawing document. Exiting.",vbOKOnly + vbExclamation,"WRONG DOCUMENT TYPE")
	Return
End If

If ThisDrawing.ModelDocument Is Nothing Then
	MsgBox("No Model Document was found for the active drawing. Exiting.",vbOKOnly + vbExclamation,"NO MODEL")
	Return
End If

Dim oMDoc As Document = ThisDrawing.ModelDocument

Dim oDtoM As String = "COPY IT FROM DRAWING TO MODEL"
Dim oMtoD As String = "COPY IT FROM MODEL TO DRAWING"
Dim oDN As String = "DO NOTHING"

Dim oWhatToDo As New ArrayList
oWhatToDo.Add(oDtoM)
oWhatToDo.Add(oMtoD)
oWhatToDo.Add(oDN)

Dim oPropSets As PropertySets = oMDoc.PropertySets
Dim oInvSumInfo As PropertySet = oPropSets.Item("Inventor Summary Information")

Dim oModelTitle As String
If oInvSumInfo.Item("Title").Value = "" Or oInvSumInfo.Item("Title").Value = vbNullString Then
	oModelTitle = ""
Else
	oModelTitle = oInvSumInfo.Item("Title").Value
End If
Dim oDrawingTitle As String
If iProperties.Value("Summary", "Title") = "" Or iProperties.Value("Summary", "Title") = vbNullString Then
	oDrawingTitle = ""
Else
	oDrawingTitle = iProperties.Value("Summary", "Title")
End If

If oModelTitle = oDrawingTitle Then
	GoTo Description
ElseIf oModelTitle <> oDrawingTitle Then
	oTitleAns = InputListBox("This Drawing's 'Title' doesn't match the referenced Model File's 'Title'." & vbCrLf & 
	"What do you want to do? ", oWhatToDo, oWhatToDo.Item(1), "TITLES DON'T MATCH", "OPTIONS")
	If oTitleAns = "" Then
		GoTo Description
	ElseIf oTitleAns = oDtoM Then
		oModelTitle = oDrawingTitle
		oMDoc.Save
	ElseIf oTitleAns = oMtoD Then
		oDrawingTitle = oModelTitle
	ElseIf oTitleAns = oDN Then
		GoTo Description
	End If
End If

Description :

Dim oDesTracProps As PropertySet = oPropSets.Item("Design Tracking Properties")
Dim oModelDesc As String
If oDesTracProps.Item("Description").Value = "" Or oDesTracProps.Item("Description").Value = vbNullString Then
	oModelDesc = ""
Else
	oModelDesc = oDesTracProps.Item("Description").Value
End If

Dim oDrawingDesc As String
If iProperties.Value("Project", "Description") = "" Or iProperties.Value("Project", "Description") = vbNullString Then
	oDrawingDesc = ""
Else
	oDrawingDesc = iProperties.Value("Project", "Description")
End If

If oModelDesc = oDrawingDesc Then
	Return
ElseIf oModelDesc <> oDrawingDesc Then
	oDescAns = InputListBox("This Drawing's 'Description' doesn't match the referenced Model File's 'Description'." & vbCrLf & 
	"What do you want to do?", oWhatToDo, oWhatToDo.Item(1), "DESCRIPTIONS DON'T MATCH", "OPTIONS")
	If oDescAns = "" Then
		Return
	ElseIf oDescAns = oDtoM Then
		oModelDesc = oDrawingDesc
		oMDoc.Save
	ElseIf oDescAns = oMtoD Then
		oDrawingDesc = oModelDesc
	ElseIf oDescAns = oDN Then
		Return
	End If
End If

InventorVb.DocumentUpdate()

 

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 10 of 15

Anonymous
Not applicable

It work! But just a point:

my drawing in "cartiglio" get description from part i put in to make the views. How can i check in the drawing if the part (ipt o iam) of the views have description blank and how i can write it from drawing to part?

 

Thank you, youre the man!

0 Likes
Message 11 of 15

WCrihfield
Mentor
Mentor

OK. Try something like this:

If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
	MsgBox("This rule only works when started from a drawing document. Exiting.",vbOKOnly + vbExclamation,"WRONG DOCUMENT TYPE")
	Return
End If

Dim oDDoc As DrawingDocument = ThisDrawing.Document

Dim oDrawingDesc As String
If iProperties.Value("Project", "Description") = "" Or iProperties.Value("Project", "Description") = vbNullString Then
	oDrawingDesc = ""
Else
	oDrawingDesc = iProperties.Value("Project", "Description")
End If

Dim oSheet As Sheet
Dim oView As DrawingView
'Dim oRefDoc As Document
Dim oMPropSet As PropertySet
Dim oModelDesc As String
For Each oSheet In oDDoc.Sheets
	For Each oView In oSheet.DrawingViews
		Dim oRefDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
		oMPropSet = oRefDoc.PropertySets.Item("Design Tracking Properties")
		If oMPropSet.Item("Description").Value = "" Or oMPropSet.Item("Description").Value = vbNullString Then
			oModelDesc = ""
		Else
			oModelDesc = oMPropSet.Item("Description").Value
		End If
		If oDrawingDesc <> oModelDesc Then
			oAns = MsgBox("The Description of the Drawing doesn't match the Model." & vbCrLf & _
			"Do you want to copy the Model Description to the Drawing?", vbYesNo + vbQuestion, "DESCRIPTION MIS-MATCH")
			If oAns = vbYes Then
				iProperties.Value("Project", "Description") = oModelDesc
			End If
		End If
	Next
Next

InventorVb.DocumentUpdate()

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 12 of 15

Anonymous
Not applicable

No error and nothing appen :V

 

How can i debug it to show why macro doesn't do nothing?

0 Likes
Message 13 of 15

WCrihfield
Mentor
Mentor

@Anonymous 

That last code shows you how to get to the document being represented within each view, but if you have multiple model files being represented within the active drawing file, you will want to somehow find which model you want to copy the description from, so it doesn't copy if from each one, for every view.

If you have a specifically named sheet & view or, just want to get the first sheet & first view, that would be easier, then you could avoid looping through all the sheets and all the views within each sheet.  Then it would only copy data one time.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 14 of 15

WCrihfield
Mentor
Mentor
Accepted solution

This is about as simple as I can make the code to copy the model's description to the drawings description, while getting the model document from a view, rather than the main model of the drawing.

I included comments above each line of code explaining what is going on.

You'll notice I am using the iProperties.Value method this time, to help simplify, but I'm not certain it will work without the mode file open, so I have a couple of lines commented out within the code, that would open the model file before attempting to access its iProperties, then a line to close it again at the end.  If the iProperties.Value() line fails, try un-commenting those two lines.

Dim oDDoc As DrawingDocument = ThisDrawing.Document

'Getting the description of the active drawing document, without checking if it is empty
Dim oDrawingDesc As String = iProperties.Value("Project", "Description")

'Getting the active sheet of the active drawing
Dim oSheet As Sheet = oDDoc.ActiveSheet

'Getting the first view that was placed into the drawing (you could specify the drawings name here too inside "" marks)
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)

'Getting the document being represented within the view
Dim oVDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument

'ThisDoc.Launch(oVDoc.FullFileName)
'Getting the model documents description iProperty value the shorter way, without checking if it is empty
Dim oVDesc As String = iProperties.Value(oVDoc, "Project", "Description")

'comparing both descriptions   <> means 'does not equal'
If oDrawingDesc <> oVDesc Then
	'attampts to set the active drawings description value to the value of the models description
	iProperties.Value("Project", "Description") = iProperties.Value(oVDoc, "Project", "Description")
End If
'oVDoc.Close
InventorVb.DocumentUpdate()

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 15 of 15

Anonymous
Not applicable

It work! Thank you

0 Likes