
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am working on a code to automate part of my drawing process (code below).
my goals are
1, to build standard views in the model - the code does this
2, start a standard drawing template
3, look at each view and set scale
the second goal I think I can work thought ( if anyone know it or has any advice and willing to share that would be great.)
but my sticking point is my third goal.
in my template I have views set, but depending on the size of model I put into this template it will change the view port area. what I want to do is have a bit of code that looks at a boundary for each view port and run though a list of scales until the first one fits.
I have started to get to grips with coding in models but not so much in drawings.
thank you in advance for your time reading this and any help is much welcome.
Sub Main () 'inputS------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Call Doit("Master", New String()(){ ({"nothing", "nothing"}), ({"nothing", "nothing"}) }) Call Doit("First", New String()(){ ({"BALL", "RED"}), ({"BOX", "GREEN"}) }) 'inputS------------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> End Sub Sub Doit (PassedViewName As String,categoryPairs as String()()) 'Return view to Home view ThisApplication.CommandManager.ControlDefinitions.Item _ ("AppViewCubeHomeCmd").Execute 'define current document Dim openDoc As Document openDoc = ThisDoc.Document Dim oAsmCompDef As AssemblyComponentDefinition oAsmCompDef = openDoc.ComponentDefinition Dim oViewRep As DesignViewRepresentation Try 'Activate a writeable View Rep (master view rep is not writeable) oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("WIP View Rep").activate Catch 'Assume error means this View Rep does not exist, so create it (will be deleted at end) oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("WIP View Rep") End Try 'Delete all existing 'CA_' View reps For Each oViewRep In oAsmCompDef.RepresentationsManager.DesignViewRepresentations If oViewRep.Name.Contains("CA_" & PassedViewName) Then oViewRep.Delete End If Next MessageBox.Show("check delete", "Title") Start: iCount = 1 'request part name. Do Until iCount = 1000 'ViewName = "CA_" & PassedViewName 'Create new View Rep oViewRep = oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Add("CA_" & PassedViewName) 'Activate new View Rep oViewRep.activate 'add in do code Call HideBreakReps(ThisDoc.Document.ComponentDefinition.Occurrences, categoryPairs) 'lock the new view rep oViewRep.Locked = True 'Zoom all ThisApplication.ActiveView.Fit '_______________________________________________________________________________________________ 'See if another View Rep is required. 'oContinue = MessageBox.Show("Add Another View Rep?" & vbLf & ViewRepCount & " View Reps Have Been Created", "Continue Creating?",MessageBoxButtons.YesNo) 'If oContinue = vbYes Then 'iCount = iCount+1 'Else iCount = 1000 'End If Loop Try 'Delete WIP View Rep oAsmCompDef.RepresentationsManager.DesignViewRepresentations.Item("WIP View Rep").delete Catch End Try End Sub 'do code Sub HideBreakReps(Occurrences As ComponentOccurrences, categoryPairs as String()()) For Each oOcc in Occurrences If oOcc.DefinitionDocumentType = kAssemblyDocumentObject Then 'MessageBox.Show(oOcc.Name, "Title") Call HideBreakReps(oOcc.SubOccurrences, categoryPairs) ElseIf oOcc.DefinitionDocumentType = kPartDocumentObject Then 'MessageBox.Show(oOcc.Name, "Title") 'MessageBox.Show(iProperties.Value (oOcc.Name,"Custom", "TYPE"), "Title") visible = True For Each categoryPair In categoryPairs cat1 = categoryPair(0) cat2 = categoryPair(1) If cat2 = "N/A" Then ' If iProperties.Value (oOcc.Name,"Custom", "TYPE") = cat1 Then If Left(iProperties.Value (oOcc.Name,"Custom", "TYPE"),Len(cat1)) = cat1 Then oOcc.Visible = False Exit For End If End If If iProperties.Value (oOcc.Name,"Custom", "TYPE") = cat1 & "." & cat2 Then visible = False Exit For End If Next oOcc.Visible = visible Else Call MsgBox("No sub-assemblies or parts found") End If Next End Sub
Solved! Go to Solution.