Hello,
my factory need a more serious implementation in the workflow between assembly IAM and drawings IDW of those assemblies.
I've collected 4-5 ilogic rules in this forums that work flawlessy each one, but i cant make them work one after another.
I've a rule called BOM (registered in the IAM template) wich create a new IDW and place the view in this IDW of the part.
In the IDW i've a rule wich extract the part list from the view and reorder it by code.
For some reasons (i think because the rule is linked to being called from a IAM file) i cant launch the resize/reorder rule from the main IDW creator rule in the IAM file, neither set the newly created IDW file as "active" and then launch its rules.
I've tried to save the newvly created idw in order to launch its itrigger on save but thisdoc.save doesent work, thisapplication.commandmanager.Startcommand(CommandIDEnum.kFileSaveCommand) works, but open a prompt to identify the name and path of the IDW, but i want to run this operation in background, as the namefile and path are fixed (ie: namefile = Assembly numeber_DT.idw, path=the same as .iam file).
RULE 1 . BOM
Dim oModel As Document Dim oModelName As String = ThisDoc.PathAndFileName(True)'"G:\#2019 - UT INVENTOR\TEST_BOM.iam" Dim oSheet As Sheet oModel= ThisApplication.Documents.Open(oModelName, False) 'Determine the drawing template Dim IDWTemplate As String = "G:\#2019 - UT INVENTOR\ZZ- Dati di progettazione\Templates 2019\DT_v1.0.idw" 'Create a drawing oDrawingDoc = ThisApplication.documents.Add(DocumentTypeEnum.kDrawingDocumentObject, IDWtemplate, True) oDrawingDoc.Activate() oSheet = oDrawingDoc.Sheets.Item(1) 'Create base view Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(25,40) oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint1, 0.2, ViewOrientationTypeEnum.kLeftViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle) Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(60,40) Dim otopview As DrawingView otopview = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) ThisApplication.CommandManager.StartCommand(CommandIDEnum.kFileSaveCommand)
Rule 2. Extract Parts List /Filter/Reorder
Dim oDoc As Document oDoc = ThisDoc.Document 'verifica se ? un disegno If oDoc.DocumentType=kDrawingDocumentObject Then Dim docFile As Document docFile = ThisDoc.ModelDocument Dim FNamePos As Long dcc=ThisApplication.Documents.Open(docFile.FullFileName,False) 'verifica che nel disegno sia caricato un assieme If dcc.DocumentType=kAssemblyDocumentObject Then Dim oBOM As BOM oBOM = dcc.ComponentDefinition.BOM oBOM.StructuredViewFirstLevelOnly = True oBOM.StructuredViewEnabled = False 'Per ogni pagina del disegno, se esiste una vista caricata, inserisce la part list Dim oSheet As Sheet For Each oSheet In oDoc.Sheets oSheet.Activate cnt=oSheet.DrawingViews.count If cnt >0 Then oDrawingView = oSheet.DrawingViews(1) Try Dim oPartslist1 As PartsList oPartslist1 = oSheet.PartsLists(1) Catch Dim oPlacementPoint As Point2d ' Dim oPartslist As PartsList' oPlacementPoint = ThisApplication.TransientGeometry.CreatePoint2d(41, 10.825)' oPartsList = oSheet.PartsLists.Add(oDrawingView, oPlacementPoint) oPlacementPoint=ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height) Dim oPartsList As PartsList oPartsList=oSheet.PartsLists.Add(oDrawingView, oPlacementPoint) minXpoint=oSheet.TitleBlock.RangeBox.MinPoint.x minYpoint=oSheet.TitleBlock.RangeBox.MaxPoint.Y maxXpoint=oPlacementPoint.x dPointx=oSheet.PartsLists.Item(1).RangeBox.MinPoint.X-minXpoint dPointY=oSheet.PartsLists.Item(1).RangeBox.MinPoint.Y-minYpoint+15 maxYpoint=oPlacementPoint.Y-dPointY Dim newmin, newmax As Point2d newmin=ThisApplication.TransientGeometry.CreatePoint2d(minXpoint, minYpoint) newmax=ThisApplication.TransientGeometry.CreatePoint2d(25, maxYpoint) oSheet.PartsLists.Item(1).Delete oPartsList=oSheet.PartsLists.Add(oDrawingView, newmax) 'rimuovo colonna pos oPartsList.PartsListColumns("POS.").Remove oPartsList.Update End Try End If Next Else MessageBox.Show("La regola funziona solo per disegni di assiemi", "iLogic") End If Else MessageBox.Show("La regola funziona solo per disegni", "iLogic") End If
' Set a reference to the drawing document. ' This assumes a drawing document is active. Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument ' Set a reference to the first parts list on the active sheet. ' This assumes that a parts list is on the active sheet. Dim oPartList As PartsList oPartList = oDrawDoc.ActiveSheet.PartsLists.Item(1) ' Iterate through the contents of the parts list. Dim i As Long Dim vTEST = "" 'da uno alla fine delle righe For i = 1 To oPartList.PartsListRows.Count 'look at only the part number column oCell = oPartList.PartsListRows.Item(i).Item("QT� UNIT�") 'find a specific value If oCell.Value = "1" Then 'hide the row oPartList.PartsListRows.Item(i).Visible = False End If Next
On Error Resume Next Dim oDrawDoc As DrawingDocument oDrawDoc = ThisApplication.ActiveDocument Dim oPartsList As PartsList oPartsList = oDrawDoc.ActiveSheet.PartsLists.Item(1) If Not oPartsList Is Nothing Then Call oPartsList.Sort("CODICE") oPartsList.Renumber oPartsList.SaveItemOverridesToBOM End If
Solved! Go to Solution.
Solved by Sergio.D.Suárez. Go to Solution.
Hi, check this rule, I made a couple of changes.
For start, keep in mind that the units by default are cm, so when you load the units put them this value.
At the end of the code, add the relocation of the partslist, modify that 2.2 to give your necessary value and it should look good.
Add a try catch end try because it did not have those columns and it was to prevent me from getting an error, I think if you remove those lines there will be no problem for your case.
Finally chuequea the numerical value when you insert the partslist, is to define what type of partslist you need if structured or only parts.
'''RULE 1 . BOM Dim oModel As Document = ThisDoc.Document 'Determine the drawing template Dim IDWTemplate As String = "G:\#2019 - UT INVENTOR\ZZ- Dati di progettazione\Templates 2019\DT_v1.0.idw" 'Create a drawing oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, IDWTemplate, True) oDrawingDoc.Activate() Dim oSheet As Sheet oSheet = oDrawingDoc.Sheets.Item(1) oSheet.Activate 'Create base view Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(2.5,4) oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint1, 0.2, ViewOrientationTypeEnum.kLeftViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle) Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(6,4) Dim otopview As DrawingView otopview = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) ' Rule 2. Extract Parts List /Filter/Reorder Dim oPlacementPoint As Point2d =ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height) Dim oPartsList As PartsList oPartsList = oSheet.PartsLists.Add(otopview, oPlacementPoint, 46593) 'kFirstLevelComponents 46593 First level components. 'kPartsOnly 46594 Parts only. 'kStructured 46593 Structured first level components. 'kStructuredAllLevels 46595 Structured all components. Try 'rimuovo colonna pos oPartsList.PartsListColumns("POS.").Remove 'da uno alla fine delle righe For i As Integer = 1 To oPartsList.PartsListRows.Count 'look at only the part number column oCell = oPartsList.PartsListRows.Item(i).Item("QTY UNITY") 'find a specific value If oCell.Value = "1" Then 'hide the row oPartsList.PartsListRows.Item(i).Visible = False End If Next Catch End Try Call oPartsList.Sort("CODICE") oPartsList.Renumber oPartsList.SaveItemOverridesToBOM oPartsList.Update 'Relocate in lower position Dim newposition As Point2d newposition = oPartsList.Position Dim oBorder As Border = oSheet.Border newposition.Y=oBorder.RangeBox.MinPoint.Y + 2.2 + (oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y) oPartsList.Position = newposition ThisApplication.CommandManager.StartCommand(CommandIDEnum.kFileSaveCommand)
I hope you find the code useful, that you modify it and adapt to your needs. regards
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
This is almost perfect, however the code throw out an error after the "hide" section, about an istance in regarding of an object.
I cannot tell why, mostly because my older code this passage got it well and your code not, i suspect it might be something regarding declaration but i cannot work it out.
I guess you will have removed the try catch end try. note that your initial code has the Item line Item("QT� UNIT�") as in many times when changing the language I had character problems, I changed them, to Item ("QTY UNITY"), check that the characters are correct otherwise you can not read the row. Grettings!!
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
You are right, i did not noted that. I will accept as solution, however i really really want to cloze and save idw as the
"IAM NAME"&"_DT" in the same folder, there is a solution for this? the popping up of the save as wizard would break all the automatic operation workflow.
Take the code that you have almost ready, and add the two lines that I detail in red, in the correct location. The first line takes the full name of the assembly without extension, and the last one saves with the name adding "_DT.idw"
'''RULE 1 . BOM Dim oModel As Document = ThisDoc.Document oFilename = ThisDoc.PathAndFileName(False) 'Determine the drawing template Dim IDWTemplate As String = "G:\#2019 - UT INVENTOR\ZZ- Dati di progettazione\Templates 2019\DT_v1.0.idw" 'Create a drawing oDrawingDoc = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, IDWTemplate, True) oDrawingDoc.Activate() Dim oSheet As Sheet oSheet = oDrawingDoc.Sheets.Item(1) oSheet.Activate 'Create base view Dim oPoint1 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(2.5,4) oBaseView = oSheet.DrawingViews.AddBaseView(oModel, oPoint1, 0.2, ViewOrientationTypeEnum.kLeftViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle) Dim oPoint2 As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(6,4) Dim otopview As DrawingView otopview = oSheet.DrawingViews.AddProjectedView(oBaseView, oPoint2, DrawingViewStyleEnum.kFromBaseDrawingViewStyle) ' Rule 2. Extract Parts List /Filter/Reorder Dim oPlacementPoint As Point2d =ThisApplication.TransientGeometry.CreatePoint2d(oSheet.Width, oSheet.Height) Dim oPartsList As PartsList oPartsList = oSheet.PartsLists.Add(otopview, oPlacementPoint, 46593) 'kFirstLevelComponents 46593 First level components. 'kPartsOnly 46594 Parts only. 'kStructured 46593 Structured first level components. 'kStructuredAllLevels 46595 Structured all components. Try 'rimuovo colonna pos oPartsList.PartsListColumns("POS.").Remove 'da uno alla fine delle righe For i As Integer = 1 To oPartsList.PartsListRows.Count 'look at only the part number column oCell = oPartsList.PartsListRows.Item(i).Item("QTY UNITY") 'find a specific value If oCell.Value = "1" Then 'hide the row oPartsList.PartsListRows.Item(i).Visible = False End If Next Catch End Try Call oPartsList.Sort("CODICE") oPartsList.Renumber oPartsList.SaveItemOverridesToBOM oPartsList.Update 'Relocate in lower position Dim newposition As Point2d newposition = oPartsList.Position Dim oBorder As Border = oSheet.Border newposition.Y=oBorder.RangeBox.MinPoint.Y + 2.2 + (oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y) oPartsList.Position = newposition 'MessageBox.Show(oFilename) oDrawingDoc.SaveAs(oFilename & "_DT.idw", False)
I hope it will help you solve your problem
Sergio Daniel Suarez
Mechanical Designer
| Upwork Profile | LinkedIn
Can't find what you're looking for? Ask the community or share your knowledge.