finally!
have code that will adjust the margin
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