Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

Use iLogic to confirm drawing is of a part or assembly

Edward_Lowe
Enthusiast

Use iLogic to confirm drawing is of a part or assembly

Edward_Lowe
Enthusiast
Enthusiast

Good Afternoon Fellow iLogic Coders,

 

I'm hoping someone in this forum can help me.  I am trying to create a rule that checks the vault status, which if approved offers the designer the chance to create a pdf of the manufacturing drawing.  Assuming the designer wants the manufacturing drawing the keep clear watermark is replaced by the manufacturing stamp (see drawing) and then saved as a pdf.  Two questions are asked once the pdf exists: 1. Does the designer want a preview of the drawing? and 2. Does the designer want the file location of the drawing opened?  Once answered the manufacturing stamp is replaced by the keep clear watermark.  I have broken down this complicated rule into four sections.  These are listed in the top left side of the attached drawing.

 

I'm struggling with section one that reads: In the drawing select 'View 1' and confirm it is a part or sheet metal part (generically speaking an ipt file)  If it is an ipt file continue onto next rule and if not exit sub.  Here is the code I have found on the forum so far:

Dim doc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = doc.ActiveSheet
Dim oView As DrawingView = oSheet.DrawingViews.Item(1)'Select View for Item number

ThisApplication.CommandManager.DoSelect(oView)'Select View

 

@JelteDeJong & @Curtis_Waguespack I thought this might be in your sweet spot.  Any help or advice is as always greatly appreciated,

Regards,

Edward

0 Likes
Reply
Accepted solutions (1)
1,840 Views
5 Replies
Replies (5)

WCrihfield
Mentor
Mentor
Accepted solution

Hi @Edward_Lowe.  It looks like you mainly need to use the DrawingView.ReferencedDocumentDescriptor.ReferencedDocument properties to get the document that the view is referencing.  Then you can just use the Document.DocumentType property to check if it is a Part.

Like this:

Dim oDDoc As DrawingDocument = ThisDoc.Document
Dim oSheet As Sheet = oDDoc.ActiveSheet
Dim oViews As DrawingViews = oSheet.DrawingViews
'get the view named "View 1"
Dim oView As DrawingView
For Each oV As DrawingView In oViews
	If oV.Name = "View 1" Then oView = oV
Next
If IsNothing(oView) Then Exit Sub
ThisApplication.CommandManager.DoSelect(oView)'Select View
Dim oViewDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
'if the model is not a part, then exit sub, else continue
If oViewDoc.DocumentType <> DocumentTypeEnum.kPartDocumentObject Then Exit Sub

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes

Edward_Lowe
Enthusiast
Enthusiast

Thank you @WCrihfield for your ilogic wisdom.  I got the code to work but noticed every time I added a drawing image the new view created added on one unit e.g. VIEW1, VIEW2, VIEW3, VIEW4 etc etc.  Is there a way I can make line 7 a multitude of views = oV?  That way if someone follows in my footsteps during testing i.e. creating four views, delete all of them and start again to create a base view: VIEW5, the code will still work,

 

Thanks and Regards,

 

Edward

0 Likes

WCrihfield
Mentor
Mentor

Hi @Edward_Lowe.  The code can definitely be done differently.  For some reason, I assumed you only wanted the code to look for a specifically named view, but that does greatly narrow the code's usefulness.  We could simply get the first view of the active sheet by its index number (oViews.Item(1)), instead of by its name, avoiding the iteration of all views on the sheet entirely.  There are also ways to check what model a drawing is referencing without even dealing with any views.  But I was not sure if your drawings are always just representing one model, or if some of your drawings may be representing multiple models.  If there is just one model, that makes it really easy, and there is a super convenient iLogic snippet just for that situation.

Dim oModelDoc As Document = ThisDrawing.ModelDocument
If oModelDoc.DocumentType = DocumentTypeEnum.kPartDocumentObject Then
	MsgBox("This drawing's 'Model' is a Part.", vbInformation, "Model Type")
ElseIf oModelDoc.DocumentType = DocumentTypeEnum.kAssemblyDocumentObject Then
	MsgBox("This drawing's 'Model' is an Assembly.", vbInformation, "Model Type")
Else
	MsgBox("This drawing's 'Model' is neither a Part, nor an Assembly.", vbInformation, "Model Type")
End If

That iLogic shortcut snippet used to set the value in that first line, looks for the first drawing view that was added to your drawing that references a model, and returns that model document.

Also, if there is just one referenced model, you could likely get it this way:

Dim oModelDoc As Document = ThisDoc.Document.ReferencedDocuments.Item(1)

 

As for step 2 of your listed objectives, about confirming Vault lifestyle status... I would not know how to check that one, because I do not currently have Vault, and I have not used it before.  Our company has considered it several times, but have not taken the final step yet.  It seems like implementing it may involve more complications for us than usual.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Edward_Lowe
Enthusiast
Enthusiast

Good Morning Wesley,  

Here are the files I mentioned in the message,

Regards,

Edward

0 Likes

ELowe6NQC6
Community Visitor
Community Visitor

I just realised I called my Drawing Template 'PartTemplate22Nov' by accident.  Attached is the template with correct description,

Regards,

Edward

0 Likes