Ilogic to scale drawing views based on model dimensions

Ilogic to scale drawing views based on model dimensions

aurel_e
Collaborator Collaborator
2,967 Views
6 Replies
Message 1 of 7

Ilogic to scale drawing views based on model dimensions

aurel_e
Collaborator
Collaborator

Hi all,

In quotation stage I use an add-in to generate a multi-sheet drawing of all the components of the assembly sent from the customer.

The problem is that some of the views are too small and some (always the flat pattern views) are bigger than the sheet. The generated views are all different scale. The drawing usually have more than 50 sheets. I cannot change or set the add-in.

I would like to have an Ilogic rule to:

-scale all the views in all the sheets based on the pars dimensions and the space in the drawing sheet.

-possibly ad a text in every sheet with the 3 parts extents dimensions.

 

2020-06-03 11_39_53-Autodesk Inventor Professional 2020.png2020-06-03 11_42_50-Autodesk Inventor Professional 2020.png

0 Likes
2,968 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

What version of Inventor are you using?

Did you know that in Inventor 2021 you can set-up Sheet Formats that can save all your view locations, all view settings for each view.  With this, all you have to do generate a new drawing with all view in place, the way you want them, is choose a Sheet Format, and BOOM...done.  All that's left is the dimensions & annotations.

 

I have an iLogic rule to create a new drawing with 4 views (regular front, top, right, & shaded ISO view) of the Active model document, which scales the views according to the model's RangeBox size compared to the available size within my drawing border.  It also orients the model on the sheet with the longest dimension along the width of the page.  But it doesn't work for drawings that already exist.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 3 of 7

aurel_e
Collaborator
Collaborator

We are using Inventor 2020.

I suppose we will install 2021 in few months. 

So you can confirm it isn't possible to achieve it with an Ilogic.

What about the second point, to have the part extents in a text?

Thanks. 

0 Likes
Message 4 of 7

fullevent
Advisor
Advisor

Hello @aurel_e,

 

I implemented something similar.
In my case the length of the axis (user parameter) is read out and a scale is defined.
Actually two, because the ISO gets another one.

 

Maybe my iLogic will help you with this.

 

2020-06-04 13_05_24-Autodesk Inventor Professional 2018 - [C58447.00-2_UR-Achse_S.idw].png

 

On Error Resume Next
Dim oDrawingDocument As Inventor.DrawingDocument
oDrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Inventor.Sheet
oSheet = oDrawingDocument.ActiveSheet
Dim oView As DrawingView
Dim oPara As UserParameters
oPara = ThisApplication.ActiveDocument.AllReferencedDocuments.Item(1).ComponentDefinition.Parameters.UserParameters

If Not oPara.Item(102).Value Then
	MessageBox.Show("Es wurde noch keine Achse mit dem Konfigurator-Tool erstellt", "Zeichnung konnte nicht erstellt werden", MessageBoxButtons.OK, MessageBoxIcon.Stop)
	Exit Sub
End If

If oPara.Item(3).Value*10 > 29400 mm Then
	Masstab1 = "1 : 60"
	Masstab2 = "1 : 110"
Else If oPara.Item(3).Value*10 > 25900 mm Then
	Masstab1 = "1 : 50"
	Masstab2 = "1 : 110"
Else If oPara.Item(3).Value*10 > 22900 mm Then
	Masstab1 = "1 : 50"
	Masstab2 = "1 : 100"
Else If oPara.Item(3).Value*10 > 21400 mm Then
	Masstab1 = "1 : 40"
	Masstab2 = "1 : 90"
Else If oPara.Item(3).Value*10 > 19900 mm Then
	Masstab1 = "1 : 40"
	Masstab2 = "1 : 85"
Else If oPara.Item(3).Value*10 > 18400 mm Then
	Masstab1 = "1 : 35"
	Masstab2 = "1 : 80"
Else If oPara.Item(3).Value*10 > 16900 mm Then
	Masstab1 = "1 : 35"
	Masstab2 = "1 : 70"
Else If oPara.Item(3).Value*10 > 14900 mm Then
	Masstab1 = "1 : 35"
	Masstab2 = "1 : 60"
Else If oPara.Item(3).Value*10 > 12800 mm Then
	Masstab1 = "1 : 30"
	Masstab2 = "1 : 50"
Else If oPara.Item(3).Value*10 > 11300 mm Then
	Masstab1 = "1 : 25"
	Masstab2 = "1 : 45"
Else If oPara.Item(3).Value*10 > 9800 mm Then
	Masstab1 = "1 : 25"
	Masstab2 = "1 : 40"
Else If oPara.Item(3).Value*10 > 5300 mm Then
	Masstab1 = "1 : 20"
	Masstab2 = "1 : 30"
Else If oPara.Item(3).Value*10 > 2300 mm Then
	Masstab1 = "1 : 15"
	Masstab2 = "1 : 25"
End If


oView = oSheet.DrawingViews.Item(1) 'regular
oView.[ScaleString] = Masstab1

oView = oSheet.DrawingViews.Item(4)	'ISO
oView.[ScaleString] = Masstab2

 

regards,


Aleksandar Krstic
Produkt- und Projektmanager

0 Likes
Message 5 of 7

WCrihfield
Mentor
Mentor

I didn't say it wasn't possible, just that I didn't have a code for that situation yet.  Here's a copy of the external iLogic rule's code that I mentioned.  It will give you some good ideas of how to do what you want.  This code is specifying a PartDocument at the start, but could easily be converted to work for an AssemblyDocument too.  Again this code is starting from the model file, to check if a drawing exists for it yet, and if not, it generates the drawing with 4 common views.  No dimensions or annotations or other complications.

But the portion of the code that retrieves the size of the model, then uses that info, along with given available drawing space, to determine the scale & orientation of each of the 4 views for the drawing it creates, could most likely be reused in your situation.

Dim oPDoc As PartDocument = ThisApplication.ActiveDocument
Dim oPDef As PartComponentDefinition = oPDoc.ComponentDefinition

If System.IO.File.Exists(ThisDoc.PathAndFileName(False) & ".idw") Then
	oOverWrite = MsgBox("A Drawing for this model already exists." & vbNewLine &
	"Do you want to over-write it?", vbYesNo + vbQuestion, "DRAWING EXISTS!")
	If oOverWrite = vbNo Then
		Return
	End If
End If

Dim oTPath As String = ThisApplication.FileOptions.TemplatesPath
Dim oTName As String = "B-SIZE STANDARD DRAWING TEMPLATE.idw"
Dim oDDoc As DrawingDocument = ThisApplication.Documents.Add(DocumentTypeEnum.kDrawingDocumentObject, oTPath & "\" & oTName, True)

'Using Measure (instead of RangeBox)
Dim oXDim As Long = Measure.ExtentsLength
Dim oYDim As Long = Measure.ExtentsWidth
Dim oZDim As Long = Measure.ExtentsHeight

''Using RangeBox for size
'Dim oRangeBox As Box = oPDef.RangeBox
'Dim oXDim As Long = (oRangeBox.MaxPoint.X - oRangeBox.MinPoint.X)
'Dim oYDim As Long = (oRangeBox.MaxPoint.Y - oRangeBox.MinPoint.Y)
'Dim oZDim As Long = (oRangeBox.MaxPoint.Z - oRangeBox.MinPoint.Z)

'MsgBox("RangeBox Size of Model = " & vbNewLine &
'oXDim & " along X Axis" & vbNewLine &
'oYDim & " along Y Axis" & vbNewLine &
'oZDim & " along Z Axis")

Dim oModelWidth As Long = MaxOfMany(oXDim, oYDim, oZDim)
Dim oModelHeight As Long = MinOfMany(oXDim, oYDim, oZDim)

'MsgBox("Longest Dim = " & oModelWidth & vbCrLf &
'"This will be used to calculate scale & view width in drawing.")

Dim oViewRotation As Double
Dim oViewOrientation As ViewOrientationTypeEnum
If oModelWidth = oXDim And oModelHeight = oYDim Then
	oViewOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
	oViewRotation = 0
ElseIf oModelWidth = oXDim And oModelHeight = oZDim Then
	oViewOrientation = ViewOrientationTypeEnum.kTopViewOrientation
	oViewRotation = 0
ElseIf oModelWidth = oYDim And oModelHeight = oXDim Then
	oViewOrientation = ViewOrientationTypeEnum.kFrontViewOrientation
	oViewRotation = (PI/2)
ElseIf oModelWidth = oYDim And oModelHeight = oZDim Then
	oViewOrientation = ViewOrientationTypeEnum.kRightViewOrientation
	oViewRotation = (PI/2)
ElseIf oModelWidth = oZDim And oModelHeight = oXDim Then
	oViewOrientation = ViewOrientationTypeEnum.kTopViewOrientation
	oViewRotation = (PI/2)
ElseIf oModelWidth = oZDim And oModelHeight = oYDim Then
	oViewOrientation = ViewOrientationTypeEnum.kRightViewOrientation
	oViewRotation = 0
End If

'Get the size of the Active Sheet
Dim oSheetWidth As Double = oDDoc.ActiveSheet.Width
Dim oSheetHeight As Double = oDDoc.ActiveSheet.Height

'Get size of area within border available for views (used for scaling views)
Dim oSideBorderOffset As Double = (.5 * 2.54)
Dim oTopBottomBorderOffset As Double = (.5 * 2.54)
Dim oTitleBlockHeight As Double = (2.5 * 2.54)
Dim oBorderWidth As Double = oSheetWidth-(oSideBorderOffset*2)
Dim oBorderHeight As Double = oSheetHeight - (oTopBottomBorderOffset * 2)
Dim oAreaAboveTitleBlock As Double = (oBorderHeight - oTopBottomBorderOffset) - oTitleBlockHeight

'Set view scale, based on model width
Dim oBViewScale As Double
If oModelWidth > (oBorderWidth/2) Then
	oBViewScale = ((oBorderWidth/2) / oModelWidth)
ElseIf oModelWidth < (oBorderWidth/2) Then
	oBViewScale = (oModelWidth / (oBorderWidth/2))
End If

inc = 1/32
oBViewScale = Round(Round((oBViewScale/2.54),5) / inc) * inc

'Try creating & placing each view at 1:1 scale, then scale to needed factor.
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oViews As DrawingViews = oDDoc.ActiveSheet.DrawingViews

Dim oFullScale As Double = 1
Dim oOriginPoint As Point2d = oTG.CreatePoint2d(0, 0)
Dim oBaseView As DrawingView = oViews.AddBaseView(oPDoc, oOriginPoint, oFullScale, _
oViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)

'Locations of view centerpoint columns & rows
Dim o1stColumn As Double = oSideBorderOffset + (oBorderWidth / 4)
Dim o2ndColumn As Double = oSideBorderOffset + ((oBorderWidth / 4) * 3)
Dim o1stRow As Double = oTopBottomBorderOffset + oTitleBlockHeight + (oAreaAboveTitleBlock/4)
Dim o2ndRow As Double = oTopBottomBorderOffset + oTitleBlockHeight + ((oAreaAboveTitleBlock/4)*3)

'Base View center point location
Dim oBaseViewLocation As Point2d = oTG.CreatePoint2d(o1stColumn, o1stRow)

'Dim oBaseView As DrawingView = oViews.AddBaseView(oPDoc, oBaseViewLocation, oBViewScale, _
'oViewOrientation, DrawingViewStyleEnum.kHiddenLineDrawingViewStyle)
oBaseView.Rotation = oViewRotation
oBaseView.Position = oBaseViewLocation
oBaseView.Scale = oBViewScale
oBaseView.ScaleString = RoundToFraction(oBViewScale,1/32,RoundingMethod.Round)
'oBaseView.Center = oBaseViewLocation
'oBaseView.RotateByAngle = 
oBaseView.IncludeMeshBodies = True
oBaseView.IncludeSurfaceBodies = True
'oBaseView.Top
'oBaseView.Height
'oBaseView.Left
'oBaseView.Width
oBaseView.Name = "BASE VIEW"
InventorVb.DocumentUpdate()
'MsgBox("Center Of View Is At:  " & oBaseView.Center.X & " , " & oBaseView.Center.Y)

'MsgBox("oBViewScale = " & oBaseView.ScaleString)


Dim oUpperViewInsPoint As Point2d = oTG.CreatePoint2d(o1stColumn, o2ndRow)
Dim oUpperView As DrawingView = oViews.AddProjectedView(oBaseView, oUpperViewInsPoint, _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oUpperView.Name = "UPPER VIEW"
oUpperView.IncludeMeshBodies = True
oUpperView.IncludeSurfaceBodies = True

Dim oRightViewInsPoint As Point2d = oTG.CreatePoint2d(o2ndColumn, o1stRow)
Dim oRightView As DrawingView = oViews.AddProjectedView(oBaseView, oRightViewInsPoint, _
DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oRightView.Name = "RIGHT VIEW"
oRightView.IncludeMeshBodies = True
oRightView.IncludeSurfaceBodies = True

Dim oISOViewInsPoint As Point2d = oTG.CreatePoint2d(o2ndColumn, o2ndRow)
Dim oISOView As DrawingView = oViews.AddProjectedView(oBaseView, oISOViewInsPoint, _
DrawingViewStyleEnum.kShadedDrawingViewStyle)
oISOView.Name = "ISO VIEW"
oISOView.IncludeMeshBodies = True
oISOView.IncludeSurfaceBodies = True

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

Message 6 of 7

sohaib.as01
Advocate
Advocate

Here is the code that i wrote to scale view to fit sheet.

What I am doing is, comparing length and width parameters to see which side is longer, since I am using A3 Landscape sheet, so I want my longest length to be along width of the sheet.  Everything else you can understand by reading the code 🙂 works fine for me. There are many other ways to go about it though, thats really a crude one I would say

ActiveSheet.View("FRONT").Scale = 1 'initiating view scale with 1
If Parameter("Lightsheet assembly.iam.LED_edge") > Parameter("Lightsheet assembly.iam.other_edge")
	ReqdW = ActiveSheet.Width / 1.7 'Width I need my view size to reduce to
	ActW = ActiveSheet.View("FRONT").Width 'getting view width whcih is my Actual width
	x = ReqdW / ActW    'factor by which the view scale is going to be reduced/increased
	ActiveSheet.View("FRONT").Scale = ActiveSheet.View("FRONT").Scale * x
Else If Parameter("Lightsheet assembly.iam.LED_edge") < Parameter("Lightsheet assembly.iam.other_edge")
	ReqdL = ActiveSheet.Height / 2.2
	ActL = ActiveSheet.View("FRONT").Height
	x = ReqdL / ActL
	ActiveSheet.View("FRONT").Scale = ActiveSheet.View("FRONT").Scale * x
Else If Parameter("Lightsheet assembly.iam.LED_edge") = Parameter("Lightsheet assembly.iam.other_edge")
	ReqdL = ActiveSheet.Height / 1.5
	ActL = ActiveSheet.View("FRONT").Height
	x = ReqdL / ActL
	ActiveSheet.View("FRONT").Scale = ActiveSheet.View("FRONT").Scale * x
End If

	ActiveSheet.View("FRONT").SetSpacingToCorner(20, 20, SheetCorner.TopLeft) 'location of FRONT view from top left corner
	ActiveSheet.View("A").SpacingBetween("FRONT") = 40 'space between FRONT and A view
	
	'Detail View location & Scale
	ActiveSheet.View("B").SetSpacingToCorner(35, 15, SheetCorner.TopRight)
	ActiveSheet.View("B").Scale = 2

 

0 Likes
Message 7 of 7

LasseBodilsen
Participant
Participant

Some necroposting here. 

I recently had to solve the same problem, but instead of looking at the part, I compared the widht of the widest view to the width of the paper.  and then set a percentage of that paper that i wanted the view to fit into. 

Calculated the new scale value, and then compared it to an array of acceptable scale values (1:1 to 1:100). 

Code: 

Sub Main()
Dim PercentageScale = 25 '<- Set desired percentage usage of paper width here:
Dim Scale = PercentageScale / 100
Dim PaperWidth = ActiveSheet.Width
Dim ScaleValues As New ArrayList

'Create Values in Scales array. (Min Scale is 1:100, Max is 1:1)
For i = 1 To 100
	ScaleValues.Add(1 / i)
Next i
 
'Get The widest View from the Current Drawing
Dim View1_Width = ActiveSheet.View("VIEW1").Width
Dim View2_Width = ActiveSheet.View("VIEW2").Width
Dim View3_Width = ActiveSheet.View("VIEW3").Width
Dim WidestView = Max(View1_Width, Max(View2_Width, View3_Width))
 
'Calculate new scale value. 
Dim WantedWidth = PaperWidth * Scale
Dim NewScale = ActiveSheet.View("VIEW1").Scale * (WantedWidth / WidestView)
Dim BestScale = Get_closest(NewScale, ScaleValues)
 
'Set Scale for All Views.
ActiveSheet.View("VIEW1").Scale = BestScale
'ActiveSheet.View("VIEW2").Scale = NewScale  '<- View2 scale is depended on View1 scale. 
ActiveSheet.View("VIEW3").Scale = BestScale
 
End Sub
 
'Function to find closest value
Function Get_closest(Number As Double, Array As ArrayList)
	CurrentValue = Array(0)
	For Each value In Array
		If Abs(Number - value) < Abs(Number - CurrentValue)
			CurrentValue = value
		End If
	Next
	Return CurrentValue
End Function


Works pretty good for the needed application
 

0 Likes