Announcements

Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.

Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drawing view placed in the wrong position

0 REPLIES 0
Reply
Message 1 of 1
mat_hijs
288 Views, 0 Replies

Drawing view placed in the wrong position

I'm trying to automate the creation of some drawings. I thought I finally got it, but when testing it, apparently it works for some models but not for others. All these models are copies from one another, so the origin is always in the same place, even the length is always the same. But still, when trying to use certain models the position is not what I'm expecting. I made a screencast showing the creation of 2 drawings as expected, but on the third drawing the position of the base view is wrong.

 

Here is the ilogic code I have:

 

Sub Main

' Set a reference to the Transaction Manager
Dim oTransactionManager As TransactionManager = ThisApplication.TransactionManager

' Start the Transaction
Dim oTransaction As Transaction = oTransactionManager.StartTransaction(ThisApplication.ActiveDocument, iLogicVb.RuleName)

' Set a reference to the Drawing Document
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument

' Set a reference to the Active Sheet
Dim oSheet As Sheet = oDoc.ActiveSheet

' Set a reference to the Drawing Views collection
Dim oDrawingViews As DrawingViews = oSheet.DrawingViews

'[ Select a Model Document from File Dialog

' Create a new File Dialog object
Dim oFileDialog As FileDialog
Call ThisApplication.CreateFileDialog(oFileDialog)

' Define the File Dialog Filter
'oFileDialog.Filter = "All Files (*.*)|*.*"
'oFileDialog.Filter = "Inventor Files (*.iam;*.ipt)|*.iam;*.ipt"
oFileDialog.Filter = "Inventor Assembly Files (*.iam)|*.iam"
'oFileDialog.Filter = "Inventor Part Files (*.ipt)|*.ipt"

' Set the title for the File Dialog
oFileDialog.DialogTitle = "Select Model Document"

' Set the initial directory that will be displayed in the File Dialog
'oFileDialog.InitialDirectory = "C:\Temp"
oFileDialog.InitialDirectory = "O:\2401_2500\2473 Commerce 46 - Brussel\I inventor\Stijlen"

' Set the flag so an error will be raised if the user clicks the Cancel button
oFileDialog.CancelError = True

' Show the Open Dialog
On Error Resume Next
oFileDialog.ShowOpen

' If an Error was raised, the user clicked cancel
If Err.Number <> 0 Then
	MsgBox("User cancelled out of dialog", , "Select Model Document")
	Exit Sub
ElseIf oFileDialog.FileName = "" Then
	MsgBox("No Model Document selected", , "Select Model Document")
	Exit Sub
End If

'MsgBox(oFileDialog.FileName, , "Select Model Document")
Dim sModelFullFileName As String = oFileDialog.FileName

' Open the Model Document
Dim sModelFullDocumentName As String = ThisApplication.FileManager.GetFullDocumentName(sModelFullFileName)
Dim oModelDoc As Document = ThisApplication.Documents.Open(sModelFullDocumentName, False)

']

'[ Create the Front View

' Set the Front View Position
Dim oFrontViewPositionX As Double = 11
Dim oFrontViewPositionY As Double = oSheet.Height / 2
Dim oFrontViewPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oFrontViewPositionX, oFrontViewPositionY)

' Set the options for the Front View
Dim oFrontViewOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	oFrontViewOptions.Add("DesignViewRepresentation", "Default")
	oFrontViewOptions.Add("DesignViewAssociative", True)

' Create the Front View
Dim oFrontView As DrawingView = oDrawingViews.AddBaseView(oModelDoc, oFrontViewPosition, 1 / 6, ViewOrientationTypeEnum.kFrontViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oFrontViewOptions)
oFrontView.Name = "Front View"

']

'[ Create the Left Side View

' Set the Left Side View Position
Dim oLeftViewPositionX As Double = oFrontViewPositionX + 6.5
Dim oLeftViewPositionY As Double = oFrontViewPositionY
Dim oLeftViewPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oLeftViewPositionX, oLeftViewPositionY)

' Set the options for the Left Side View
Dim oLeftViewOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	oLeftViewOptions.Add("DesignViewRepresentation", "Default")
	oLeftViewOptions.Add("DesignViewAssociative", True)

' Create the Left Side View
Dim oLeftView As DrawingView = oDrawingViews.AddProjectedView(oFrontView, oLeftViewPosition, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oLeftView.Name = "Left View"

']

'[ Create the Right Side View

' Set the Right Side View Position
Dim oRightViewPositionX As Double = oFrontViewPositionX - 6.5
Dim oRightViewPositionY As Double = oFrontViewPositionY
Dim oRightViewPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oRightViewPositionX, oRightViewPositionY)

' Set the options for the Right Side View
Dim oRightViewOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	oRightViewOptions.Add("DesignViewRepresentation", "Default")
	oRightViewOptions.Add("DesignViewAssociative", True)

' Create the Right Side View
Dim oRightView As DrawingView = oDrawingViews.AddProjectedView(oFrontView, oRightViewPosition, DrawingViewStyleEnum.kFromBaseDrawingViewStyle)
oRightView.Name = "Right View"

']

'[ Create the Top View

' Set the Top View Position
Dim oTopViewPositionX As Double = oSheet.Width - 11
Dim oTopViewPositionY As Double = oSheet.Height - 6.5
Dim oTopViewPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oTopViewPositionX, oTopViewPositionY)

' Set the options for the Top View
Dim oTopViewOptions As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
	oTopViewOptions.Add("DesignViewRepresentation", "Default")
	oTopViewOptions.Add("DesignViewAssociative", True)

' Create the Top View
Dim oTopView As DrawingView = oDrawingViews.AddBaseView(oModelDoc, oTopViewPosition, 1 / 2.5, ViewOrientationTypeEnum.kTopViewOrientation, DrawingViewStyleEnum.kHiddenLineRemovedDrawingViewStyle, , , oTopViewOptions)
oTopView.Name = "Top View"

']

'[ Create a Break

CreateVerticalBreak(oFrontView, (50) + 350, (50 + 2640) -350)

']

'[ Create Linear Dimensions

CreateLinearDimension(oSheet, oFrontView, "Links", 2, "WPL_Onderkant", "WPL_Bovenkant")

CreateLinearDimension(oSheet, oFrontView, "Links", 1, "WPL_Onderkant", "WPL_As_Regel_L1")
CreateLinearDimension(oSheet, oFrontView, "Links", 1, "WPL_As_Regel_L1", "WPL_As_Regel_L2")
CreateLinearDimension(oSheet, oFrontView, "Links", 1, "WPL_As_Regel_L2", "WPL_As_Regel_L3")
CreateLinearDimension(oSheet, oFrontView, "Links", 1, "WPL_As_Regel_L3", "WPL_As_Regel_L4")
CreateLinearDimension(oSheet, oFrontView, "Links", 1, "WPL_As_Regel_L4", "WPL_Bovenkant")

CreateLinearDimension(oSheet, oFrontView, "Rechts", 2, "WPL_Onderkant", "WPL_Bovenkant")

CreateLinearDimension(oSheet, oFrontView, "Rechts", 1, "WPL_Onderkant", "WPL_As_Regel_R1")
CreateLinearDimension(oSheet, oFrontView, "Rechts", 1, "WPL_As_Regel_R1", "WPL_As_Regel_R2")
CreateLinearDimension(oSheet, oFrontView, "Rechts", 1, "WPL_As_Regel_R2", "WPL_As_Regel_R3")
CreateLinearDimension(oSheet, oFrontView, "Rechts", 1, "WPL_As_Regel_R3", "WPL_As_Regel_R4")
CreateLinearDimension(oSheet, oFrontView, "Rechts", 1, "WPL_As_Regel_R4", "WPL_Bovenkant")

']

'[ Create a Parts List
' Set a reference to the sheet's Title Block
Dim oTitleBlock As TitleBlock = oSheet.TitleBlock

' Set the Parts List Position
Dim oTempPartsListPosition As Point2d = oTitleBlock.RangeBox.MaxPoint

' Create the Parts List
Dim oPartsList As PartsList = oSheet.PartsLists.Add(oFrontView, oTempPartsListPosition, PartsListLevelEnum.kStructured)
oPartsList.Style = "Hegge NV Parts List Type 2"

' Move the Parts List to the correct Position
Dim oPartsListHeight As Double = oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y
Dim oPartsListPosition As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oTempPartsListPosition.X, oTempPartsListPosition.Y + oPartsListHeight)
oPartsList.Position = oPartsListPosition

']

' End the Transaction
oTransaction.End

End Sub

Function CreateVerticalBreak(ByVal oDrawingView As DrawingView, oStartpointYModel As Double, oEndpointYModel As Double)
	
	' Set references to documents, sheets, views and component definitions
	Dim oModelAsm As AssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oModelAsmCompDef As AssemblyComponentDefinition = oModelAsm.ComponentDefinition
	Dim oModelPart As ComponentOccurrence = oModelAsmCompDef.Occurrences.ItemByName("Profiel")
	Dim oModelPartDoc As PartDocument = oModelPart.Definition.Document
	Dim oModelPartCompDef As PartComponentDefinition = oModelPartDoc.ComponentDefinition
	
	' Get positions of view extents
	Dim oDrawingViewLeft As Double = oDrawingView.Left
	Dim oDrawingViewRight As Double = oDrawingView.Left + oDrawingView.Width
	Dim oDrawingViewTop As Double = oDrawingView.Top
	Dim oDrawingViewBottom As Double = oDrawingView.Top - oDrawingView.Height
	
	' Get Scale of view
	Dim oDrawingViewScale As Double = oDrawingView.Scale
	
	' Set start and end point of break
	Dim oCenterPointX As Double = oDrawingView.Center.X
	Dim oStartpointY As Double = oDrawingViewBottom + oStartpointYModel / 10 * oDrawingViewScale
	Dim oEndpointY As Double = oDrawingViewBottom + oEndpointYModel / 10 * oDrawingViewScale
	
	Dim oStartpoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oCenterPointX, oStartpointY)
	Dim oEndpoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oCenterPointX, oEndpointY)
	
	' Create break
	Dim oBreakOperation As BreakOperation = oDrawingView.BreakOperations.Add(BreakOrientationEnum.kVerticalBreakOrientation, oStartpoint, oEndpoint, BreakStyleEnum.kStructuralBreakStyle)
	
End Function

Function CreateLinearDimension(ByVal oSheet As Sheet, ByVal oDrawingView As DrawingView, oZijdeMaat As String, oNiveauMaat As Double, oWPlane1Naam As String, oWPlane2Naam As String)
'Function CreateLinearDimension(oZijdeMaat As String, oNiveauMaat As Double, oWPlane1Naam As String, oWPlane2Naam As String)
	
	' Set references to documents, and component definitions
	Dim oModelAsm As AssemblyDocument = oDrawingView.ReferencedDocumentDescriptor.ReferencedDocument
	Dim oModelAsmCompDef As AssemblyComponentDefinition = oModelAsm.ComponentDefinition
	Dim oModelPart As ComponentOccurrence = oModelAsmCompDef.Occurrences.ItemByName("Profiel")
	Dim oModelPartDoc As PartDocument = oModelPart.Definition.Document
	Dim oModelPartCompDef As PartComponentDefinition = oModelPartDoc.ComponentDefinition

	' Set references to workplanes
	Dim oWPlane1 As WorkPlane = oModelPartCompDef.WorkPlanes.Item(oWPlane1Naam)
	Dim oWPlane2 As WorkPlane = oModelPartCompDef.WorkPlanes.Item(oWPlane2Naam)

	' Create proxies for workplanes
	Dim oWPlane1Proxy As WorkPlaneProxy
	 oModelPart.CreateGeometryProxy(oWPlane1, oWPlane1Proxy)

	Dim oWPlane2Proxy As WorkPlaneProxy
	 oModelPart.CreateGeometryProxy(oWPlane2, oWPlane2Proxy)

	' Include workplanes and turn visibility off
	oDrawingView.SetIncludeStatus(oWPlane1Proxy, True)
	oDrawingView.SetVisibility(oWPlane1Proxy, False)

	oDrawingView.SetIncludeStatus(oWPlane2Proxy, True)
	oDrawingView.SetVisibility(oWPlane2Proxy, False)

	' Create geometry intents for workplanes
	Dim oWPlane1Intent As GeometryIntent
	Dim oWPlane2Intent As GeometryIntent
	Dim oCenterline As Centerline

	For Each oCenterline In oSheet.Centerlines
	    If oCenterline.ModelWorkFeature Is oWPlane1Proxy Then
	        oWPlane1Intent = oSheet.CreateGeometryIntent(oCenterline)
	    ElseIf oCenterline.ModelWorkFeature Is oWPlane2Proxy Then
	        oWPlane2Intent = oSheet.CreateGeometryIntent(oCenterline)
	    End If
	Next

	' Set spacing between dimensions
	Dim oDimSpacing As Double = 1

	' Get positions of view extents
	Dim oDrawingViewLeft As Double = oDrawingView.Left
	Dim oDrawingViewRight As Double = oDrawingView.Left + oDrawingView.Width

	' Set level of dimension
	Dim oDimensionLevel As Double = oNiveauMaat

	' Set dimension position
	Dim oDrawingViewDimPosition As Double
	If oZijdeMaat = "Links" Then
		oDrawingViewDimPosition = oDrawingViewLeft
	ElseIf oZijdeMaat = "Rechts" Then
		oDrawingViewDimPosition = oDrawingViewRight
	End If

	' Create transient point
	Dim oPointX As Double
	If oZijdeMaat = "Links" Then
		oPointX = oDrawingViewDimPosition - oDimensionLevel * oDimSpacing
	ElseIf oZijdeMaat = "Rechts" Then
		oPointX = oDrawingViewDimPosition + oDimensionLevel * oDimSpacing
	End If

	Dim oPointY As Double = 0
	Dim oPoint As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(oPointX, oPointY)

	' Create linear dimension
	Dim oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
	Dim oLinearDimLengte = oGeneralDims.AddLinear(oPoint, oWPlane1Intent, oWPlane2Intent)
	oLinearDimLengte.CenterText
	
End Function

 I'm desperately trying to find out how to avoid this because having to move all the view manually kind of defeats the whole point. Here is the link to the screencast: https://autode.sk/3MDxVv2 

0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report