Hello.
If I have used a Button on a Form, I must first click in Inventor to access it again.
I'm trying to get focus using this code but it doesn't seem to work.
'Set focus back to Inventor application
Dim App As Process() = Process.GetProcessesByName("Inventor 2022")
If App.Length > 0 Then
AppActivate(App(0).Id)
End If
Anyone?
Hello.
If I have used a Button on a Form, I must first click in Inventor to access it again.
I'm trying to get focus using this code but it doesn't seem to work.
'Set focus back to Inventor application
Dim App As Process() = Process.GetProcessesByName("Inventor 2022")
If App.Length > 0 Then
AppActivate(App(0).Id)
End If
Anyone?
What do you use:
form.show
or
form.showdialog
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
What do you use:
form.show
or
form.showdialog
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
Neither, I mean a Global Form that is open next to Inventor with some buttons on it that address another External Rule.
See picture.
Neither, I mean a Global Form that is open next to Inventor with some buttons on it that address another External Rule.
See picture.
This is the setup from the form, see picture.
This is the setup from the form, see picture.
I need to see the code of the form and of the button!
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
I need to see the code of the form and of the button!
Regards,
Arthur Knoors
Autodesk Affiliations:
Autodesk Software:Inventor Professional 2024 | Vault Professional 2022 | Autocad Mechanical 2022
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:Drawing List!|Toggle Drawing Sheet!|Workplane Resize!|Drawing View Locker!|Multi Sheet to Mono Sheet!|Drawing Weld Symbols!|Drawing View Label Align!|Open From Balloon!|Model State Lock!
Posts and Ideas:Dimension Component!|Partlist Export!|Derive I-properties!|Vault Prompts Via API!|Vault Handbook/Manual!|Drawing Toggle Sheets!|Vault Defer Update!
! For administrative reasons, please mark a "Solution as solved" when the issue is solved !
That is a collection of separate rules, see zip as attachment.
Form in 'UI' zip.
Most rules are a 'pass through' to the 'main' rule 'Scale Position Views' according:
' Check file type
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
' Run external rule with parameters
' Fill argument's list
Dim map As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim SetScale As String = "Scale All Bigger"
map.Add("SetScale", SetScale)
auto = iLogicVb.Automation
auto.RunExternalRuleWithArguments(oDoc, "Scale Position Views", map)
End If
In other words, 'Scale Position Views' is the linchpin in the whole.
I also try to get the focus there at the end.
See 'Scale Position Views' code:
'Dim obj As DrawingView
' obj = RuleArguments("DrawingView")
' AddBallonToView(obj)
'MessageBox.Show(RuleArguments("ScaleAllBigger"))
Dim SetScale As String = RuleArguments("SetScale")
Dim SetSheetFormat As String = RuleArguments("SetSheetFormat")
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView
Dim lScales As New List(Of Double)
lScales.AddRange({0.2, 0.25, 0.333333333333, 0.5, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 25, 30, 40, 50, 75, 100 })
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oSheetWidth As Double = oDoc.ActiveSheet.Width
Dim oSheetHeight As Double = oDoc.ActiveSheet.Height
Dim oTitleBlock As TitleBlock = oSheet.TitleBlock
Dim oSideBorderOffset As Double = (0.5)
Dim oTopBottomBorderOffset As Double = (0.5)
Dim oTitleBlockHeight As Double = (6.5)
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
' Set PartsList position
Dim x As Double = 0
Dim y As Double = 0
Try
Dim oPartsList As PartsList
oPartsList = oSheet.PartsLists.Item(1)
' Dim insertPoint As Point2d = oTG.CreatePoint2d(0, 0)
' Dim PartsList As PartsList = oSheet.PartsLists.Add(oSheet.DrawingViews.Item(1), insertPoint)
' Dim ooPartsList As PartsList = oSheet.PartsLists.Add(oSheet.DrawingViews.Item(1), insertPoint, PartsListLevelEnum.kPartsOnly)
' ooPartsList.HeadingPlacement = HeadingPlacementEnum.kHeadingAtBottom
' ooPartsList.TableDirection = TableDirectionEnum.kBottomUpDirection
Dim plHeight = oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y
Dim plWidth = oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X
'MessageBox.Show("plWidth: " & plWidth)
x = oTitleBlock.RangeBox.MaxPoint.X
y = oTitleBlock.RangeBox.MaxPoint.Y + plHeight
oPartsList.Position = oTG.CreatePoint2d(x, y)
oPartsList.PartsListRows(0).Height = 5
For Each oRow In oPartsList.PartsListRows
oRow.Height = .5
Next
Catch
End Try
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
' Located at the beginning of the rule to keep it as fast as possible
' If the views are already unsuppressed then calulate/position them again
Dim bAllViewsAlreadyUnsuppressed As Boolean = True
If SetScale = "Unsuppress Aditional Views" Then
For Each oView In oSheet.DrawingViews
If oView.Suppressed = True Then
oView.Suppressed = False
Else
bAllViewsAlreadyUnsuppressed = False
End If
'xMin = oView.Left
'xMax = oView.Left + oView.Width
'yMin = oView.Top - oView.Height
'yMax = oView.Top
'If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then oView.ShowLabel = True ' View = outside border
Next
If bAllViewsAlreadyUnsuppressed = True Then Exit Sub
End If
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Do your thing")
' Determine the Distances between Views to maintain after scaling
Dim oDistBaseRightView As Double
Dim oDistBaseTopView As Double
Dim oDistBaseLeftView As Double
Dim oDistRightBackView As Double
Dim oDistBaseBottomView As Double
Dim oDistBaseBackView As Double
Dim xMaxBase As Double ' = ActiveSheet.View("BASE VIEW").Center.X
Dim xMinBase As Double
Dim yMaxBase As Double
Dim yMinBase As Double
Dim xMinRight As Double
Dim xMaxRight As Double
Dim yMinTop As Double
Dim xMaxLeft As Double
Dim xMinBack As Double
Dim yMaxBottom As Double
Dim oBaseView As DrawingView ' = oSheet.DrawingViews("BASE VIEW")
Dim oRightView As DrawingView
Dim oTopView As DrawingView
Dim oLeftView As DrawingView
Dim oBackView As DrawingView
Dim oBottomView As DrawingView
Dim oISOFrontView As DrawingView
Dim oISOLeftView As DrawingView
Dim oISOFrontBottomView As DrawingView
Dim oISOLeftBottomView As DrawingView
Dim oISORightView As DrawingView
Dim oISOBackView As DrawingView
Dim oISORightBottomView As DrawingView
Dim oISOBackBottomView As DrawingView
For Each oView In oSheet.DrawingViews
If oView.Name = "BASE VIEW" Then
oBaseView = oView
xMaxBase = oView.Left + oView.Width
xMinBase = oView.Left
yMaxBase = oView.Top
yMinBase = oView.Top - oView.Height
End If
If oView.Name = "RIGHT VIEW" Then
oRightView = oView
xMinRight = oView.Left
xMaxRight = oView.Left + oView.Width
End If
If oView.Name = "TOP VIEW" Then
oTopView = oView
yMinTop = oView.Top - oView.Height
End If
If oView.Name = "LEFT VIEW" Then
oLeftView = oView
xMaxLeft = oView.Left + oView.Width
End If
If oView.Name = "BACK VIEW" Then
oBackView = oView
xMinBack = oView.Left
End If
If oView.Name = "BOTTOM VIEW" Then
oBottomView = oView
yMaxBottom = oView.Top
End If
Next
oDistBaseRightView = xMinRight - xMaxBase
oDistBaseTopView = yMinTop - yMaxBase
oDistBaseLeftView = xMinBase - xMaxLeft
oDistRightBackView = xMinBack - xMaxRight
oDistBaseBottomView = yMinBase - yMaxBottom
oDistBaseBackView = xMinBack - xMaxBase
For Each oView In oSheet.DrawingViews
Try
xMin = oView.Left
xMax = oView.Left + oView.Width
yMin = oView.Top - oView.Height
yMax = oView.Top
xTarget = 0
xCurrent = 0
yTarget = 0
yCurrent = 0
x = oView.Center.X
y = oView.Center.Y
If SetScale = "Scale All Bigger" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val - 1)
Catch
End Try
End If
If SetScale = "Scale All Smaller" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val + 1)
Catch
End Try
End If
If SetScale = "Scale ISO Bigger" Then
If oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val - 1)
Catch
End Try
End If
End If
If SetScale = "Scale ISO Equal" Then
If oView.Name Like "*ISO*" Then
oView.Scale = (oSheet.DrawingViews.Item(1).Scale)
End If
End If
If SetScale = "Scale ISO Smaller" Then
If oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val + 1)
Catch
End Try
End If
End If
If SetScale = "Scale ISO Standard Position" Then
' See below in Code under 'If oView.Name = "ISO FRONT VIEW" Then'
End If
If SetScale = "Scale Other Bigger" Then
If Not oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val - 1)
Catch
End Try
End If
End If
If SetScale = "Scale Other Smaller" Then
If Not oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val + 1)
Catch
End Try
End If
End If
If SetScale = "Unsuppress Aditional Views" Then
' See above in Code
End If
If SetScale = "Suppress Aditional Views" Then
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth or xMin < 0 Or yMax > oSheetHeight Or yMin < 0 Then ' View = outside border
oView.Suppressed = True
oView.ShowLabel = True
End If
End If
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
If oView.Name = "BASE VIEW" Then
oBaseView = oView
oView.Center = oTG.CreatePoint2d((oView.Width / 2) + xMin , y)
oview.ShowLabel = False
End If
If oView.Name = "RIGHT VIEW" Then
oRightView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth Or xMin < 0) And oView.ShowLabel = True Then ' View = outside border
RightViewIsOutsideBorder = True ' To set BackView when RightView is outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
xCurrent = xMin
Else
oView.ShowLabel = False
xTarget = oBaseView.Left + oBaseView.Width + oDistBaseRightView
xCurrent = oView.Left
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "TOP VIEW" Then
oTopView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or yMax > oSheetHeight Or yMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
yTarget = oBaseView.Top + oDistBaseTopView
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "LEFT VIEW" Then
oLeftView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth Or xMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oView.Width
xCurrent = xMin
Else
oView.ShowLabel = False
xTarget = oBaseView.Left - oDistBaseLeftView - oView.Width
xCurrent = oView.Left
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "BACK VIEW" Then
oBackView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth or xMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
If RightViewIsOutsideBorder Then xTarget = oSheetWidth + 7 + oRightView.Width + 3 ' Place at right side from oRightView which is outside border
xCurrent = xMin
Else
oView.ShowLabel = False
xTarget = oRightView.Left + oRightView.Width + oDistRightBackView
If RightViewIsOutsideBorder Then xTarget = oBaseView.Left + oBaseView.Width + oDistBaseBackView ' Place at right side from oRightView which is outside border
xCurrent = xMin
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "BOTTOM VIEW" Then
oBottomView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or yMax > oSheetHeight Or yMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
yTarget = oBaseView.Top - oBaseView.Height - oDistBaseBottomView - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO FRONT VIEW" Then
oISOFrontView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oView.Width
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
If SetScale = "Scale ISO Standard Position" Then
xTarget = oSheetWidth - oSideBorderOffset - 1 - oView.Width
xCurrent = oView.Left
yTarget = oSheetHeight - oTopBottomBorderOffset - 1 - oView.Height
yCurrent = oView.Top - oView.Height
Else
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO LEFT VIEW" Then
oISOLeftView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oISOFrontView.Width - 5 - oView.Width
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO FRONT BOTTOM VIEW" Then
oISOFrontBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oView.Width
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO LEFT BOTTOM VIEW" Then
oISOLeftBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oISOFrontBottomView.Width - 5 - oView.Width
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO RIGHT VIEW" Then
oISORightView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO BACK VIEW" Then
oISOBackView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5 + oISORightView.Width + 5
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO RIGHT BOTTOM VIEW" Then
oISORightBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO BACK BOTTOM VIEW" Then
oISOBackBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5 + oISORightView.Width + 5
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
Catch
End Try
Next
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
trans.End()
''Set focus back to Inventor application
'Dim App As Process() = Process.GetProcessesByName("Inventor 2022")
'If App.Length > 0 Then
' AppActivate(App(0).Id)
'End If
That is a collection of separate rules, see zip as attachment.
Form in 'UI' zip.
Most rules are a 'pass through' to the 'main' rule 'Scale Position Views' according:
' Check file type
If ThisApplication.ActiveDocumentType = DocumentTypeEnum.kDrawingDocumentObject Then
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
' Run external rule with parameters
' Fill argument's list
Dim map As NameValueMap = ThisApplication.TransientObjects.CreateNameValueMap
Dim SetScale As String = "Scale All Bigger"
map.Add("SetScale", SetScale)
auto = iLogicVb.Automation
auto.RunExternalRuleWithArguments(oDoc, "Scale Position Views", map)
End If
In other words, 'Scale Position Views' is the linchpin in the whole.
I also try to get the focus there at the end.
See 'Scale Position Views' code:
'Dim obj As DrawingView
' obj = RuleArguments("DrawingView")
' AddBallonToView(obj)
'MessageBox.Show(RuleArguments("ScaleAllBigger"))
Dim SetScale As String = RuleArguments("SetScale")
Dim SetSheetFormat As String = RuleArguments("SetSheetFormat")
Dim oDoc As DrawingDocument = ThisApplication.ActiveDocument
Dim oSheet As Sheet = oDoc.ActiveSheet
Dim oView As DrawingView
Dim lScales As New List(Of Double)
lScales.AddRange({0.2, 0.25, 0.333333333333, 0.5, 1, 2, 3, 4, 5, 6, 8, 10, 12, 15, 20, 25, 30, 40, 50, 75, 100 })
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oSheetWidth As Double = oDoc.ActiveSheet.Width
Dim oSheetHeight As Double = oDoc.ActiveSheet.Height
Dim oTitleBlock As TitleBlock = oSheet.TitleBlock
Dim oSideBorderOffset As Double = (0.5)
Dim oTopBottomBorderOffset As Double = (0.5)
Dim oTitleBlockHeight As Double = (6.5)
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
' Set PartsList position
Dim x As Double = 0
Dim y As Double = 0
Try
Dim oPartsList As PartsList
oPartsList = oSheet.PartsLists.Item(1)
' Dim insertPoint As Point2d = oTG.CreatePoint2d(0, 0)
' Dim PartsList As PartsList = oSheet.PartsLists.Add(oSheet.DrawingViews.Item(1), insertPoint)
' Dim ooPartsList As PartsList = oSheet.PartsLists.Add(oSheet.DrawingViews.Item(1), insertPoint, PartsListLevelEnum.kPartsOnly)
' ooPartsList.HeadingPlacement = HeadingPlacementEnum.kHeadingAtBottom
' ooPartsList.TableDirection = TableDirectionEnum.kBottomUpDirection
Dim plHeight = oPartsList.RangeBox.MaxPoint.Y - oPartsList.RangeBox.MinPoint.Y
Dim plWidth = oPartsList.RangeBox.MaxPoint.X - oPartsList.RangeBox.MinPoint.X
'MessageBox.Show("plWidth: " & plWidth)
x = oTitleBlock.RangeBox.MaxPoint.X
y = oTitleBlock.RangeBox.MaxPoint.Y + plHeight
oPartsList.Position = oTG.CreatePoint2d(x, y)
oPartsList.PartsListRows(0).Height = 5
For Each oRow In oPartsList.PartsListRows
oRow.Height = .5
Next
Catch
End Try
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
' Located at the beginning of the rule to keep it as fast as possible
' If the views are already unsuppressed then calulate/position them again
Dim bAllViewsAlreadyUnsuppressed As Boolean = True
If SetScale = "Unsuppress Aditional Views" Then
For Each oView In oSheet.DrawingViews
If oView.Suppressed = True Then
oView.Suppressed = False
Else
bAllViewsAlreadyUnsuppressed = False
End If
'xMin = oView.Left
'xMax = oView.Left + oView.Width
'yMin = oView.Top - oView.Height
'yMax = oView.Top
'If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then oView.ShowLabel = True ' View = outside border
Next
If bAllViewsAlreadyUnsuppressed = True Then Exit Sub
End If
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
Dim trans As Transaction = ThisApplication.TransactionManager.StartTransaction(oDoc, "Do your thing")
' Determine the Distances between Views to maintain after scaling
Dim oDistBaseRightView As Double
Dim oDistBaseTopView As Double
Dim oDistBaseLeftView As Double
Dim oDistRightBackView As Double
Dim oDistBaseBottomView As Double
Dim oDistBaseBackView As Double
Dim xMaxBase As Double ' = ActiveSheet.View("BASE VIEW").Center.X
Dim xMinBase As Double
Dim yMaxBase As Double
Dim yMinBase As Double
Dim xMinRight As Double
Dim xMaxRight As Double
Dim yMinTop As Double
Dim xMaxLeft As Double
Dim xMinBack As Double
Dim yMaxBottom As Double
Dim oBaseView As DrawingView ' = oSheet.DrawingViews("BASE VIEW")
Dim oRightView As DrawingView
Dim oTopView As DrawingView
Dim oLeftView As DrawingView
Dim oBackView As DrawingView
Dim oBottomView As DrawingView
Dim oISOFrontView As DrawingView
Dim oISOLeftView As DrawingView
Dim oISOFrontBottomView As DrawingView
Dim oISOLeftBottomView As DrawingView
Dim oISORightView As DrawingView
Dim oISOBackView As DrawingView
Dim oISORightBottomView As DrawingView
Dim oISOBackBottomView As DrawingView
For Each oView In oSheet.DrawingViews
If oView.Name = "BASE VIEW" Then
oBaseView = oView
xMaxBase = oView.Left + oView.Width
xMinBase = oView.Left
yMaxBase = oView.Top
yMinBase = oView.Top - oView.Height
End If
If oView.Name = "RIGHT VIEW" Then
oRightView = oView
xMinRight = oView.Left
xMaxRight = oView.Left + oView.Width
End If
If oView.Name = "TOP VIEW" Then
oTopView = oView
yMinTop = oView.Top - oView.Height
End If
If oView.Name = "LEFT VIEW" Then
oLeftView = oView
xMaxLeft = oView.Left + oView.Width
End If
If oView.Name = "BACK VIEW" Then
oBackView = oView
xMinBack = oView.Left
End If
If oView.Name = "BOTTOM VIEW" Then
oBottomView = oView
yMaxBottom = oView.Top
End If
Next
oDistBaseRightView = xMinRight - xMaxBase
oDistBaseTopView = yMinTop - yMaxBase
oDistBaseLeftView = xMinBase - xMaxLeft
oDistRightBackView = xMinBack - xMaxRight
oDistBaseBottomView = yMinBase - yMaxBottom
oDistBaseBackView = xMinBack - xMaxBase
For Each oView In oSheet.DrawingViews
Try
xMin = oView.Left
xMax = oView.Left + oView.Width
yMin = oView.Top - oView.Height
yMax = oView.Top
xTarget = 0
xCurrent = 0
yTarget = 0
yCurrent = 0
x = oView.Center.X
y = oView.Center.Y
If SetScale = "Scale All Bigger" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val - 1)
Catch
End Try
End If
If SetScale = "Scale All Smaller" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val + 1)
Catch
End Try
End If
If SetScale = "Scale ISO Bigger" Then
If oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val - 1)
Catch
End Try
End If
End If
If SetScale = "Scale ISO Equal" Then
If oView.Name Like "*ISO*" Then
oView.Scale = (oSheet.DrawingViews.Item(1).Scale)
End If
End If
If SetScale = "Scale ISO Smaller" Then
If oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val + 1)
Catch
End Try
End If
End If
If SetScale = "Scale ISO Standard Position" Then
' See below in Code under 'If oView.Name = "ISO FRONT VIEW" Then'
End If
If SetScale = "Scale Other Bigger" Then
If Not oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val - 1)
Catch
End Try
End If
End If
If SetScale = "Scale Other Smaller" Then
If Not oView.Name Like "*ISO*" Then
Dim oBViewScale As Double = (1 / oView.Scale)
Dim Val As Double = lScales.IndexOf(oBViewScale)
Try
oView.Scale = 1 / lScales.Item(Val + 1)
Catch
End Try
End If
End If
If SetScale = "Unsuppress Aditional Views" Then
' See above in Code
End If
If SetScale = "Suppress Aditional Views" Then
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth or xMin < 0 Or yMax > oSheetHeight Or yMin < 0 Then ' View = outside border
oView.Suppressed = True
oView.ShowLabel = True
End If
End If
' -------------------------------------------------------------------------------------------------------------------------------------------------------------
If oView.Name = "BASE VIEW" Then
oBaseView = oView
oView.Center = oTG.CreatePoint2d((oView.Width / 2) + xMin , y)
oview.ShowLabel = False
End If
If oView.Name = "RIGHT VIEW" Then
oRightView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth Or xMin < 0) And oView.ShowLabel = True Then ' View = outside border
RightViewIsOutsideBorder = True ' To set BackView when RightView is outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
xCurrent = xMin
Else
oView.ShowLabel = False
xTarget = oBaseView.Left + oBaseView.Width + oDistBaseRightView
xCurrent = oView.Left
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "TOP VIEW" Then
oTopView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or yMax > oSheetHeight Or yMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
yTarget = oBaseView.Top + oDistBaseTopView
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "LEFT VIEW" Then
oLeftView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth Or xMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oView.Width
xCurrent = xMin
Else
oView.ShowLabel = False
xTarget = oBaseView.Left - oDistBaseLeftView - oView.Width
xCurrent = oView.Left
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "BACK VIEW" Then
oBackView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or xMax > oSheetWidth or xMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
If RightViewIsOutsideBorder Then xTarget = oSheetWidth + 7 + oRightView.Width + 3 ' Place at right side from oRightView which is outside border
xCurrent = xMin
Else
oView.ShowLabel = False
xTarget = oRightView.Left + oRightView.Width + oDistRightBackView
If RightViewIsOutsideBorder Then xTarget = oBaseView.Left + oBaseView.Width + oDistBaseBackView ' Place at right side from oRightView which is outside border
xCurrent = xMin
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "BOTTOM VIEW" Then
oBottomView = oView
If (xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Or yMax > oSheetHeight Or yMin < 0) And oView.ShowLabel = True Then ' View = outside border
oView.ShowLabel = True
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
yTarget = oBaseView.Top - oBaseView.Height - oDistBaseBottomView - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO FRONT VIEW" Then
oISOFrontView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oView.Width
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
If SetScale = "Scale ISO Standard Position" Then
xTarget = oSheetWidth - oSideBorderOffset - 1 - oView.Width
xCurrent = oView.Left
yTarget = oSheetHeight - oTopBottomBorderOffset - 1 - oView.Height
yCurrent = oView.Top - oView.Height
Else
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO LEFT VIEW" Then
oISOLeftView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oISOFrontView.Width - 5 - oView.Width
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO FRONT BOTTOM VIEW" Then
oISOFrontBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oView.Width
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO LEFT BOTTOM VIEW" Then
oISOLeftBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = 0 - 5 - oISOFrontBottomView.Width - 5 - oView.Width
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO RIGHT VIEW" Then
oISORightView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO BACK VIEW" Then
oISOBackView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5 + oISORightView.Width + 5
xCurrent = oView.Left
yTarget = oSheetHeight + 5
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO RIGHT BOTTOM VIEW" Then
oISORightBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
If oView.Name = "ISO BACK BOTTOM VIEW" Then
oISOBackBottomView = oView
If xMax < 0 Or xMin > oSheetWidth Or yMax < 0 Or yMin > oSheetHeight Then ' View = outside border
oView.ShowLabel = True
xTarget = oSheetWidth + 5 + oISORightView.Width + 5
xCurrent = oView.Left
yTarget = 0 - 5 - oView.Height
yCurrent = oView.Top - oView.Height
Else
oView.ShowLabel = False
xTarget = xMax - oView.Width
xCurrent = oView.Left
yTarget = yMax - oView.Height
yCurrent = oView.Top - oView.Height
End If
oView.Center = oTG.CreatePoint2d(oView.Position.X + (xTarget - xCurrent), oView.Position.Y + (yTarget - yCurrent))
End If
Catch
End Try
Next
'----------------------------------------------------------------------------------------------------
' Undo Wrapper
trans.End()
''Set focus back to Inventor application
'Dim App As Process() = Process.GetProcessesByName("Inventor 2022")
'If App.Length > 0 Then
' AppActivate(App(0).Id)
'End If
Can't find what you're looking for? Ask the community or share your knowledge.