OK. Here is a much longer version of the code, in which I've added a lot of error checking code to help eliminate possible errors, and inform you better about any errors that do still happen. If you still receive error message with this code, please provide screen captures of each tab of the error messages in the next post so we can better understand them. Also, if you see any of the messages I have inserted into the code as error checks, let us know about those too.
Also, if this code still doesn't fix the problem, or at least let us know better where the problem is, we may need to see the contents of those other rules you are trying to run. Even though they may work OK when ran individually from the model file, we may need to make slight changes to them that will allow them to work better when being ran from the drawing this way. A common problem in this type of situation, is when the other rules refer to their target document as 'ThisApplication.ActiveDocument', when the active document is almost always the document that is open/active when the original rule is ran (in this case the drawing). Sometimes you can change this reference in the other rules to ThisDoc.Document to fix this, but not always.
Anyways, here's the newly expanded code for you to try: (I've included lots of comment lines in there too.)
'Making sure the 'active' document is a Drawing document
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly + vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
'defining the variable as a DrawingDocument, and setting its value
Dim oDDoc As DrawingDocument = ThisDrawing.Document
'Now ckecking to make sure this drawing has a Model document (to help eliminate possible errors)
If ThisDrawing.ModelDocument Is Nothing Then
MsgBox("The model document for this drawing was not found. Exiting.", vbOKOnly + vbCritical, "MODEL NOT FOUND")
Exit Sub
End If
'Now we're checking the 'model' document's DocumentType,
'to make sure it is not only a Part but a Sheet Metal Part.
If ThisDrawing.ModelDocument.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then
MsgBox("The 'model' document is an assembly. It must be a Sheet Metal Part for this rule to work. Exiting.", vbOKOnly + vbCritical, "Wrong Model Type")
Exit Sub
End If
'defining the variable as a PartDocument, and setting its value, now that we know for sure that is is a Part
'Also just to make absolutely sure the Model document is open and active,
'since we will be dealing with it first, before the drawing
Dim oMDoc As PartDocument = ThisApplication.Documents.Open(ThisDrawing.ModelDocument.FullDocumentName, False)
oMDoc.Activate
'now we need to make sure it is a Sheet Metal Part, not just a regular Part
'There is more than one way to check this, but I like to check within its iProperties
'the document needs to be open (at some capacity) before you can check its iProperties
If oMDoc.PropertySets.Item("Design Tracking Properties").Item("Document SubType Name") <> "Sheet Metal" Then
MsgBox("The model is a Part, but not a Sheet Metal Part. Exiting.", vbOKOnly + vbCritical, "NOT SHEET METAL")
Exit Sub
End If
Dim oAuto As IiLogicAutomation = iLogicVb.Automation
Try
oAuto.RunExternalRule(oMDoc, "BurnNumber")
Catch oEx As Exception
MsgBox("Something went wrong while trying to run 'BurnNumber'." & vbCrLf & _
"The Error Message is as follows:" & vbCrLf & _
oEx.Message & vbCrLf & vbCrLf & _
"Its 'StackTrace' is as follows:" & vbCrLf & _
oEx.StackTrace & vbCrLf & vbCrLf & _
"Its 'Source' is as follows:" & vbCrLf & _
oEx.Source, vbOKOnly + vbExclamation, " ")
End Try
Try
oAuto.RunExternalRule(oMDoc, "DXFit")
Catch oEx As Exception
MsgBox("Something went wrong while trying to run 'DXFit'." & vbCrLf & _
"The Error Message is as follows:" & vbCrLf & _
oEx.Message & vbCrLf & vbCrLf & _
"Its 'StackTrace' is as follows:" & vbCrLf & _
oEx.StackTrace & vbCrLf & vbCrLf & _
"Its 'Source' is as follows:" & vbCrLf & _
oEx.Source, vbOKOnly + vbExclamation, " ")
End Try
Try
oDDoc.Activate
Catch
End Try
Try
'oMDoc.Save
oMDoc.Close(True) 'True means Skip Saving
Catch
oMDoc.ReleaseReference
Finally
'do nothing.
'you may not even need to close it since your active drawing is still referencing it.
'when you close the drawing, it will likely release the reference to the model file too
End Try
Try
oAuto.RunExternalRule(oDDoc, "PDFit")
Catch oEx As Exception
MsgBox("Something went wrong while trying to run 'PDFit'." & vbCrLf & _
"The Error Message is as follows:" & vbCrLf & _
oEx.Message & vbCrLf & vbCrLf & _
"Its 'StackTrace' is as follows:" & vbCrLf & _
oEx.StackTrace & vbCrLf & vbCrLf & _
"Its 'Source' is as follows:" & vbCrLf & _
oEx.Source, vbOKOnly + vbExclamation, " ")
End Try
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click 'LIKE' 👍.
Wesley Crihfield

(Not an Autodesk Employee)