cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Drawing View, Hidden Line Calculation, Margin DEFAULT Value

Drawing View, Hidden Line Calculation, Margin DEFAULT Value

Hi,

I have looked through the application options and the Styles & Standards for this.

Since there is not user-configurable value I'd like to suggest a way to add one.

 

The attached image below is a screen-capture of the drawing view creation dialog box, showing the Model State tab.

I have highlighted the MARGIN field for clarity.  Currently, the value in this field is automatically generated based on unknown parameters.  It seems there is no user control over this value.  Fixing it on every view placement wastes time.

 

I have 100 drawings to create every month, with 100's of view to insert and most of them needs a margin of about 100 units, not 0.21 as shown.

To create these drawings and views, we are forced to re-type a number in this box.  Every time.  Furthermore, when a view is created without the reference lines shown, it can't be placed in the right spot.  Adjusting the margin after the view is created then requires moving the views around again.  To do it once takes 30 seconds.  To do it 100 times wastes an hour.

 

To remove this tedious exercise, a default value could be made available to users that is saved either with the drawing template (preferred) or with the application styles.  I can suggest a few places if this doesn't seem obvious.

 

Thanks.

Steven

 drawing view margin.PNG

42 Comments
pete.dehaan
Contributor

This still seems to an issue and there is no access via the API to allow iLogic to automate it.

Yijiang.Cai
Autodesk

@pete.dehaan I would like to confirm your request here. Are you talking about the API support to settings related to reference data in the dialog? Many thanks!

francis.korde
Advocate

Hello,
@Yijiang.Cai I'm just jumping into the discussion to say that we're also wasting a lot of time with this setting. And also that I'd prefer to have a default value that we could adjust. We always use values that allow us to see all of our parts in references and as they are generally the same size, the value is always the same.

pete.dehaan
Contributor

I agree, there should be defaults that can be set for this, probably in application options > Drawings. And also API calls for the settings of how reference BOM structured items are displayed. That way we can easily fix drawing views created before a default gets implemented.

 

I have been unable to find any way to work with the following via iLogic or VBA.

  1. Reference data hidden line calculation is set to "All Bodies"
  2. Display style for reference data set to "Edges as Part"
  3. Reference data "Margin" is set to "100".

 

 

maxim.teleguz
Advocate

@pete.dehaan 

here is as close as i could get to working with margin and code:

this retrieves what you should set your margin to:

Sub Main
    ' Iterate through all sheets in the drawing
    Dim DrawingDoc As Inventor.DrawingDocument = ThisDrawing.Document
    For Each DwgSheet As Inventor.Sheet In DrawingDoc.Sheets
        ' Iterate through all views on the sheet
        For Each DwgView As Inventor.DrawingView In DwgSheet.DrawingViews
            ' Retrieve the margin value for each drawing view
            Dim MarginValue As Double = GetViewMargin(DwgView)
            ' Print or use the margin value as needed
            MsgBox("Margin value for view: " & MarginValue)
        Next
    Next
End Sub

Private Function GetViewMargin(DwgView As Inventor.DrawingView) As Double
    ' Get the size of the drawing view
    Dim viewWidth As Double = DwgView.Width
    Dim viewHeight As Double = DwgView.Height
    Dim marginX As Double = viewWidth
    Dim marginY As Double = viewHeight
    ' Return the calculated margin value
    Return marginX ' Assuming uniform margin, you can return marginX or marginY
End Function
pete.dehaan
Contributor

Thanks Maxim,

If we are eventually able to set the margin then this could be more useful than just using a static and large value such as 100.

maxim.teleguz
Advocate

@pete.dehaan it would speed up complex drawings a thousand fold too. instead of waiting on inventorviewcompute.exe this whole thing can be faster. 

Daniel.buzinari
Advocate

It is weird that such a basic setting is still pending implementation.

 

I constantly work with existing references in my models and the default setting is very confusing to the eye, I also use if as All Bodies, Edge as Parts and the Margin I adjust to my needs.

 

The only thing we can change from what I see is the Layer, it would be great to be able to customise and save the settings for the Reference Data / Hidden Line Calculation

 

 

pete.dehaan
Contributor

This might be helpful for some of you.

I was working on updating our drawing styles today and realized I could use this to solve part of the issue.

Under your Object Defaults you can change the "Reference Part Edge" object type to a Visible Edges for the layer.

mikeh4
Collaborator

Believe the full discussion revolves around Reference parts as margins on "Normal" parts is never an issue and frankly never needed to care about it.  From the functional perspective if a REF part is turned on in a view the margin needs to be include the REF parts in that calculation to determine where the margin is measuring from.  I want to call it a JDI project, but on the programming side it's probably much more involved than that.

 

Regards

maxim.teleguz
Advocate

here is the code to update margin! i will still be updating this to work on all the views since it doesnt always work yet. but time will cure that. 


 

Sub Main()

    Dim oApp As Inventor.Application = ThisApplication

    ' Ensure a drawing document is active
    Dim oDrawingDoc As Inventor.DrawingDocument = Nothing
    If oApp.ActiveDocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
        oDrawingDoc = oApp.ActiveDocument
    Else
        MessageBox.Show("Please open a drawing document first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    End If

    ' Prompt the user to select a specific view
    Dim SelectedView As Inventor.DrawingView = Nothing
    Try
        SelectedView = oApp.CommandManager.Pick(SelectionFilterEnum.kDrawingViewFilter, "Select a Detail or Section View")
    Catch ex As Exception
        MessageBox.Show("Error selecting view: " & ex.Message, "Selection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    End Try

    ' Check if a view was selected
    If SelectedView Is Nothing Then
        MessageBox.Show("No view was selected. Exiting.", "Selection Cancelled", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Exit Sub
    End If

    ' Calculate a margin from the selected view using your logic
    Dim CalculatedMargin As Double = GetViewMargin(SelectedView)

    ' If it’s a DetailDrawingView
    If TypeOf SelectedView Is DetailDrawingView Then
        Dim oDetailView As DetailDrawingView = CType(SelectedView, DetailDrawingView)
        Dim currentMargin As Double = oDetailView.Margin
        MessageBox.Show("Current Detail View Margin: " & currentMargin & vbCrLf & _
                        "Calculated Margin: " & CalculatedMargin, "Margin", MessageBoxButtons.OK, MessageBoxIcon.Information)

        ' Set the margin from the calculated value
        oDetailView.Margin = CalculatedMargin
        oDrawingDoc.Update()
        MessageBox.Show("Detail View Margin updated to " & CalculatedMargin, "Margin Updated", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Exit Sub
    End If

    ' If it’s a SectionDrawingView
    If TypeOf SelectedView Is SectionDrawingView Then
        Dim oSectionView As SectionDrawingView = CType(SelectedView, SectionDrawingView)
        Dim currentMargin As Double = oSectionView.Margin
        MessageBox.Show("Current Section View Margin: " & currentMargin & vbCrLf & _
                        "Calculated Margin: " & CalculatedMargin, "Margin", MessageBoxButtons.OK, MessageBoxIcon.Information)

        ' Set the margin from the calculated value
        oSectionView.Margin = CalculatedMargin
        oDrawingDoc.Update()
        MessageBox.Show("Section View Margin updated to " & CalculatedMargin, "Margin Updated", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Exit Sub
    End If

    ' If it’s neither detail nor section
    MessageBox.Show("Selected view is not a Detail or Section view. No margin property available.", "Not Applicable", MessageBoxButtons.OK, MessageBoxIcon.Information)

End Sub

Private Function GetViewMargin(DwgView As Inventor.DrawingView) As Double
    ' Example calculation:
    ' Currently, this just returns the width of the view as the margin.
    ' Adjust this logic to whatever makes sense for your scenario.
    
    Dim viewWidth As Double = DwgView.Width
    Dim viewHeight As Double = DwgView.Height
    ' For now, just return viewWidth. You can implement a more complex calculation if needed.
    Return viewWidth
End Function

 

@pete.dehaan Your method works perfectly for me and saves changing settings in each view, thank you.

pete.dehaan
Contributor

This is frustrating.

Made one step forward setting the hidden line calculation to use "All Bodies" instead of "Reference Data Separately".

 

Reference:

https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=DrawingView_HiddenLineCalculationForAllBodies

 

However, the other step needed is to change the margin value and this still doesn't seem to work, even though it does seem to be a read / write property now.

 

Reference:
https://help.autodesk.com/view/INVNTOR/2025/ENU/?guid=DrawingView_Margin

 

I am on Inventor Pro 2024, maybe this works on newer versions? 

maxim.teleguz
Advocate

@pete.dehaan  why are you not using my code

pete.dehaan
Contributor

@maxim.teleguz 

Tried out your script, it did not modify the margins.

I noted that you mentioned it doesn't work 100% of the time, were you able to determine the cause?

Which version of Inventor do you have it running on?

 

Thanks.

maxim.teleguz
Advocate

here is an updated version of the script:

you can change the 10 to whatever margin you want the code to trigger on, so if the margin is bigger than 10 it will run on that view.

Sub Main()

    Dim oApp As Inventor.Application = ThisApplication
	
	If oApp.ActiveDocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
        Exit Sub
    End If

'    ' Ensure a drawing document is active
    Dim oDrawingDoc As Inventor.DrawingDocument = Nothing
    If oApp.ActiveDocumentType = Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
        oDrawingDoc = oApp.ActiveDocument
    Else
'        MessageBox.Show("Please open a drawing document first.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Exit Sub
    End If

    Dim optimizeNeeded As Boolean = False

    ' Loop through all sheets and their views to see if any view has a margin > 50
    Dim oSheet As Sheet
    Dim oView As DrawingView

    For Each oSheet In oDrawingDoc.Sheets
        For Each oView In oSheet.DrawingViews
            Try
				If oView.Margin > 10 Then
                    optimizeNeeded = True
                    Exit For
                End If
            Catch
                ' If a view does not support the margin property, ignore it.
            End Try
        Next
        If optimizeNeeded Then Exit For
    Next

    ' If no view has a margin > 50, then exit.
    If Not optimizeNeeded Then Exit Sub

    ' Ask the user if they want to optimize all view margins.
    Dim result As DialogResult = MessageBox.Show("One or more views have a user entered margin greater than it should be." & vbCrLf & _
                                                  "This will degrade downstream performance on this drawing." & vbCrLf & _
                                                  "Would you like to optimize all view margins?", _
                                                  "Optimize View Margins", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    If result <> DialogResult.Yes Then Exit Sub

    ' Loop through all views and update the margin using the existing logic.
    For Each oSheet In oDrawingDoc.Sheets
        For Each oView In oSheet.DrawingViews
            Try
                Dim calculatedMargin As Double = GetViewMargin(oView)
                If TypeOf oView Is DetailDrawingView Then
                    Dim oDetailView As DetailDrawingView = CType(oView, DetailDrawingView)
                    oDetailView.Margin = calculatedMargin
                ElseIf TypeOf oView Is SectionDrawingView Then
                    Dim oSectionView As SectionDrawingView = CType(oView, SectionDrawingView)
                    oSectionView.Margin = calculatedMargin
                Else
                    ' error check for DrawingViews
                    oView.Margin = calculatedMargin
                End If
            Catch
                ' Silently skip any view that cannot be updated.
            End Try
        Next
    Next

	oDrawingDoc.Update()
	MessageBox.Show("Optimized margins for all applicable views.", "Update Complete", MessageBoxButtons.OK, MessageBoxIcon.Information)


End Sub

Private Function GetViewMargin(DwgView As Inventor.DrawingView) As Double
    ' Your current logic for calculating the margin remains unchanged.
    Dim viewWidth As Double = DwgView.Width
    Dim viewHeight As Double = DwgView.Height
    Return viewWidth
End Function

 

maxim.teleguz
Advocate

i am running 2023

pete.dehaan
Contributor

Huzzah, that works!

pete.dehaan
Contributor

Here is my version, it sets the Hidden Line Calculation to "All Bodies" and then uses a modified version of maxim's code to calculate the appropriate margin value. It does this for all views of all sheets in the active drawing.

' Description:
' This rule runs two separate processes to update all views on all sheets.
' 1. It sets the hidden line calculation properties for all views.
' 2. It calculates and applies the appropriate margin to all applicable views using a
'    working method from the Autodesk forums.
'==================================================================================================================

Sub Main()
    ' First, check if the active document is a drawing.
    If ThisApplication.ActiveDocumentType <> Inventor.DocumentTypeEnum.kDrawingDocumentObject Then
        MessageBox.Show("This rule can only be run in a drawing document.", "iLogic - Wrong Document Type", MessageBoxButtons.OK, MessageBoxIcon.Warning)
        Return
    End If

    Dim oDrawDoc As Inventor.DrawingDocument = ThisApplication.ActiveDocument

    ' --- Run Processes Separately ---
    ' Process 1: Apply the hidden line settings to all views.
    ApplyHiddenLineSettings(oDrawDoc)

    ' Process 2: Apply the margin settings to all views.
    OptimizeViewMargins(oDrawDoc)

    ' --- Final Document Update ---
    oDrawDoc.Update()
    iLogicVb.UpdateWhenDone = True
    
    ' Final message is commented out for fully silent operation.
    'MessageBox.Show("View settings have been updated.", "iLogic Rule Complete", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Sub

Private Sub ApplyHiddenLineSettings(oDrawDoc As Inventor.DrawingDocument)
    Logger.Info("Starting: ApplyHiddenLineSettings")
    For Each oSheet As Sheet In oDrawDoc.Sheets
        For Each oView As DrawingView In oSheet.DrawingViews
            Try
                oView.HiddenLineCalculationForAllBodies = True
                oView.ShowReferenceComponentsInHiddenLines = False
            Catch ex As Exception
                Logger.Error("Could not set hidden lines for view '" & oView.Name & "'. Error: " & ex.Message)
            End Try
        Next
    Next
    Logger.Info("Finished: ApplyHiddenLineSettings")
End Sub

Private Sub OptimizeViewMargins(oDrawDoc As Inventor.DrawingDocument)
    Logger.Info("Starting: OptimizeViewMargins")
    
    ' --- Main Processing Loop ---
    ' The pre-check has been removed to ensure the margin is calculated and applied to all views every time.
    For Each oSheet As Sheet In oDrawDoc.Sheets
        For Each oView As DrawingView In oSheet.DrawingViews
            Try
                Dim calculatedMargin As Double = GetViewMargin(oView)
                If TypeOf oView Is DetailDrawingView Then
                    CType(oView, DetailDrawingView).Margin = calculatedMargin
                ElseIf TypeOf oView Is SectionDrawingView Then
                    CType(oView, SectionDrawingView).Margin = calculatedMargin
                Else
                    oView.Margin = calculatedMargin
                End If
            Catch
                ' Silently skip any view that cannot be updated.
            End Try
        Next
    Next
    Logger.Info("Finished: OptimizeViewMargins")
End Sub

Private Function GetViewMargin(DwgView As Inventor.DrawingView) As Double
    ' This function EXACTLY mimics the successful forum script.
    ' 1. It READS multiple properties from the view (Width and Height).
    ' 2. It RETURNS one of those property's values.
    ' This "read-then-write" process is the key to making the margin update work.
    Dim viewWidth As Double = DwgView.Width
    Dim viewHeight As Double = DwgView.Height
    Return viewWidth
End Function

 

Thanks @maxim.teleguz 

maxim.teleguz
Advocate

@pete.dehaan teamwork is wonderful

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

Submit Idea