Ilogic Drawing view scale

Ilogic Drawing view scale

Anonymous
Not applicable
3,634 Views
2 Replies
Message 1 of 3

Ilogic Drawing view scale

Anonymous
Not applicable

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

0 Likes
Accepted solutions (1)
3,635 Views
2 Replies
Replies (2)
Message 2 of 3

Anonymous
Not applicable

The "DrawingView" Object includes properties of "Length", "Width", and "Scale". 

 

If you already have your Views in the drawing, and properties linked to the base view, you can set the scale with this. 

 

Dim oDwgDoc as Document
Set oDwgDoc = ThisApplication.ActiveDocument 'assuming you are running it from the current document, otherwise reference the correct file here.  
Dim oSheet as Sheet Set oSheet = oDwgDoc.Sheets.Item(1) 'assuming we are working on the first sheet Dim oView as DrawingView Set oView = oSheet.DrawingViews.Item(1) 'assuming the base view is the first view
Dim ViewWide as Long ViewWide = 5 'change this to how wide you want your view to be oView.Scale = ViewWide/oView.Width

 

Disclaimer, i didn't test this, but i have something similar running in iLogic. 

Message 3 of 3

Anonymous
Not applicable
Accepted solution

Ended up testing it. 

 

Sub DrawingViewScale()
    Dim oDwgDoc As Document
    Set oDwgDoc = ThisApplication.ActiveDocument 'assuming you are running it from the current document, otherwise reference the correct file here.
    Dim oSheet As Sheet
    Set oSheet = oDwgDoc.Sheets.Item(1) 'assuming we are working on the first sheet
    
    Dim oView As DrawingView
    Set oView = oSheet.DrawingViews.Item("1") 'assuming the base view is the first view
    oView.ScaleString = "1:1"
    
    Dim ViewWide As Double
    ViewWide = 5 'change this to how wide you want your view to be
    
    Dim DrawingScale As String
    DrawingScale = CStr(ViewWide / oView.Width)

    oView.ScaleString = DrawingScale
End Sub