iLogic- dele base view in drawing if the part is not in part list

iLogic- dele base view in drawing if the part is not in part list

t.slosar
Participant Participant
1,114 Views
10 Replies
Message 1 of 11

iLogic- dele base view in drawing if the part is not in part list

t.slosar
Participant
Participant

Hello, 

could please somebody help me with ilogic rule? I need to delete all base views in drawing only if the part number is not in part list. 

 

Thanks a lot 

0 Likes
Accepted solutions (1)
1,115 Views
10 Replies
Replies (10)
Message 2 of 11

WCrihfield
Mentor
Mentor

Do you need the rule to process multiple (all) sheets in the drawing at once, or just the 'active' sheet in the drawing?

Is there just one Parts List in the whole drawing document, or are there varying parts lists on each sheet?  If there is a different parts list on each sheet, then does the code need to only check the views on each sheet against the parts list on that same sheet?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 11

t.slosar
Participant
Participant

Hi,

I have one part list, but sometimes more sheets in one drawing document. 

0 Likes
Message 4 of 11

WCrihfield
Mentor
Mentor
Accepted solution

OK. I think I may have something for you.  This iLogic rule will first attempt to get the first Parts List in your drawing document, from whichever sheet it may be on, if any.  If it doesn't find one, it will let you know and exit the rule.  It then starts looping through each sheet, and each view on the sheet, retrieving the model document's Part Number, then attempting to search through the Parts List found earlier for that Part Number.  If it is not found, it will attempt to delete that drawing view.

Here's the iLogic rule code:

Sub Main
	If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
		MsgBox("A Drawing Document must be active for this rule to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
		Exit Sub
	End If
	Dim oDDoc As DrawingDocument = ThisApplication.ActiveDocument
	Dim oSheet As Sheet

	' get Parts List to reference
	Dim oPList As PartsList
	For Each oSheet In oDDoc.Sheets
		If oSheet.PartsLists.Count > 0 Then
			oPList = oSheet.PartsLists.Item(1)
			Exit For
		End If
	Next
	If IsNothing(oPList) Then
		MsgBox("No Parts List found. Exiting.", , "")
		Exit Sub
	End If

	'now start checking views on all sheets
	For Each oSheet In oDDoc.Sheets
		For Each oView As DrawingView In oSheet.DrawingViews
			'get Part Number of document in that view
			Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
			Dim oPN As String = oDoc.PropertySets(3).Item("Part Number").Value
			'check for it in the Parts List
			If Not PNinPList(oPN, oPList) Then
				Try
					oView.Delete
				Catch
					MsgBox("The attempt to delete the view failed.",,"")
				End Try
			End If
		Next
	Next
End Sub

Function PNinPList(ByVal oPNum As String, oPtList As PartsList) As Boolean
	Dim oResult As Boolean = False
	'check if specified Part Number (oPNum) is found in the specified Parts List (oPtList)
	'I don't know if you have a column for Part Number or how you may have it labeled,
	'so I'll retrieve the Part Number from each row the hard way to be sure
	For Each oRow As PartsListRow In oPtList.PartsListRows
		If oRow.ReferencedRows.Count > 0 Then
			Dim oRefRow As DrawingBOMRow = oRow.ReferencedRows.Item(1)
			If oRefRow.BOMRow.ComponentDefinitions.Count > 0 Then
				Dim oRefDoc As Document = oRefRow.BOMRow.ComponentDefinitions.Item(1).Document
				If oPNum = oRefDoc.PropertySets(3).Item("Part Number").Value Then
					oResult = True
				End If
			End If
		End If
	Next
	Return oResult
End Function

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 💡or you can Explore My CONTRIBUTIONS

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 5 of 11

t.slosar
Participant
Participant

Oh my.. works perfect. Just one more question. I have in drawing many base view- main welding assembly consists of plates. 

All plates part number start with "ENG", main assy start "A".

I have base view of main assy also in drawing but not in part list, so I add "And Left(oPN,3)="ENG" Then"

'check for it in the Parts List
			If Not PNinPList(oPN, oPList) And Left(oPN,3)="ENG" Then
				Try
					oView.Delete
				Catch
					MsgBox("The attempt to delete the view failed.",,"")

 It seems this work well. But to be sure, could you please confirm me it´s correct? 

Thansk a lot

0 Likes
Message 6 of 11

WCrihfield
Mentor
Mentor

Just so I understand what you are attempting to do with this change...

  • You want to avoid any views of your main assembly from being deleted when this code runs, right?
    • Maybe check if PN starts with "A", and if so, don't delete them
  • Do you want all of the views of these 'plates', whose part numbers start with "ENG" to all be deleted?
    • ...Or just delete the views of the plates with PN starting with "ENG", whose part numbers don't show up in the Parts List?

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 7 of 11

t.slosar
Participant
Participant

Hi,

I want delete all base view start witch "ENG" which is not in part list. 

 

Example, I have assembly and I´ll make copy design (with drawing). In drawing there is base view of all ENG parts (all sheet metal plates from assy). When I remove (delete) sheet metal plate from assy, base view of this ENG part remain. But in assy and also in part list this sheet metal is already deleted. 

 

I already add: Left(oPN,3)="ENG", see more from code above.

 

If Not PNinPList(oPN, oPList) And Left(oPN,3)="ENG" Then

Thanks 

0 Likes
Message 8 of 11

WCrihfield
Mentor
Mentor

OK. I understand now.  I believe that should work just fine then.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 9 of 11

G.Binl
Advocate
Advocate

Hello @WCrihfield 

Hope you are well, This works great.

Would this be able to be reversed and add a Base view for each item missing?

Example would be small assemble with 3 parts a,b & c

if you have the main assembly say, 1xxx that contains a,b,c in its parts list. can each part be fetched to create a base view a, base view b & base view c in a drawing?

0 Likes
Message 10 of 11

WCrihfield
Mentor
Mentor

Hi @G.Binl.  Sure sounds possible/doable to me.  Of course creating and placing drawing views of models into a drawing is a lot more complicated than simply deleting them.  We would have to know on what sheet(s) to place them, where on the sheet to place them, what size to make the views, what orientation, what view style (hidden lines, no hidden lines, shaded), what design view to use (if any), what model state or LOD to use (if any), etc, etc, etc.

Drawing automation can get pretty complicated, depending on what all you are planning on doing, and can vary greatly from one individual to the next.  It requires knowledge and familiarity of the drawing templates being used, company specific drawing styles/standards/procedures, a great amount of knowledge of the models being documented, and often a lot of planning/preparation.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 11 of 11

G.Binl
Advocate
Advocate

Thanks@WCrihfield a lot of our files are a set standard, LOD is the same, scale can be auto-size if thats not an option we will set a standard size. The drawing template is set. my goal is to get a single view of each sub assemble that is known on each sheet first from the assembly in any order. then we will run other rules separately to clean and organize each sheets with the finer details. i have managed to use a counter (1) get the path () and file name (3) of each sub assembly. right now its with the model assemble open.

GarrettBingle_1-1646780180681.png

 

 

0 Likes