- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I've put together a rule that can reposition a detail view on to a work point. This rule was working the other day but now its saying that the 'object reference is not set to an instance of an object'
For reference, the rule is below.
I'm not sure what the problem is because when I read the type of the object "oDetailView.Type.ToString" I get what I would expect, "kDetailDrawingViewObject", but when I try to write to "oDetailView.FenceCornerTwo.X" for example, it says this object is not set. I'm confused because it seems like it would be the same object and because its a detail drawing view object, it should have fence corners, (it is rectangular). It also was working recently. Any thoughts on what I'm missing? thanks, Dustin
'/////////////////////////////////////////////////////////////////////////////////////////////// ' ---Create or Position Detail View--- '----------------------------------------------------------------------------------------------- ' Description: ' This rule will create or position a detail view at a named work point at the top level of a ' model. Supported view orientation: ' Top, Bottom, Front, Back, Right, Left, Bottom 180, Back 180, Right 90 and Left 270 '----------------------------------------------------------------------------------------------- ' Calling method example: '[Create or Position Detail View 'SharedVariable("CreatePosition") = "Create" 'Create/Position Create new view/position existin view 'SharedVariable("BaseViewName") = "TOP" ' "View Name" 'SharedVariable("WorkPointName") = "Work Point 1" ' "Work Point Name" 'SharedVariable("DetailViewName") = "A" ' "Detail View Name" 'The following shared viariable are only required for the "Create" option 'SharedVariable("DetailViewWScale") = .375 'SharedVariable("DetailViewVerticalPos") = 50 'Percentatge across the sheet from left 'SharedVariable("DetailViewHorizontalPos") = 50 'Percentatge across the sheet from bottom 'SharedVariable("FenceSize") = 2 'Numeric Value, Rad. or Rect. Height 'SharedVariable("FenceWidth") = 2 'Numeric Value, Rect. Width 'SharedVariable("FenceShape") = "Circ" ' "Rect"/"Circ" 'SharedVariable("Debug") = False 'iLogicVb.RunExternalRule("Create or Position Detail View") '] '----------------------------------------------------------------------------------------------- '[ Rule explanation and iLogic tracking log start entry 'This rule handles the values that are sent down to the sub-components of the assembly 'and getting text parameter values from a sub-component. 'SharedVariable("RuleName") = "Drawing Parameter Control" 'SharedVariable("RulePrefix") = "Start" 'iLogicVb.RunExternalRule("Application iLogic Tracking Log Entry") '] Dim oDrawDoc As DrawingDocument = ThisApplication.ActiveDocument Dim oSheet, oSheetTemp As Sheet Dim oViewLooper, oViewTemp, oView As DrawingView Dim oAssyDoc As AssemblyDocument Dim oWP, oSelectedWP As WorkPoint Dim oTG As TransientGeometry = ThisApplication.TransientGeometry Dim oPointBase, oPointCorner1, oPointCorner2, oViewOrigin, oViewWP As Point2d Dim MinQuandrant As Integer = 0 Dim RotateCounter As Integer = 0 Dim BaseViewOrientation As String Dim Undo As Transaction Dim X2D As Double Dim Y2D As Double Dim X3D As Double Dim Y3D As Double Dim Z3D As Double Dim CreatePosition As String Dim BaseViewName As String Dim WorkPointName As String Dim DetailViewName As String Dim DetailViewWScale As String Dim DetailViewVerticalPos As Integer Dim DetailViewHorizontalPos As Integer Dim FenceSize As Double Dim FenceWidth As Double Dim FenceShape As String Dim FenceSizeSet As Boolean Dim Debug As Boolean '[Checks document type If Not ThisDoc.Document.DocumentType = kDrawingDocumentObject Then MessageBox.Show("'Create or Position Detail View' only works in a drawing.", _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 0 'Exits Rule End If '] '[Check for shared variables If SharedVariable.Exists("CreatePosition") Then CreatePosition = SharedVariable("CreatePosition") SharedVariable.Remove("CreatePosition") If CreatePosition = "Create" elseIf CreatePosition = "Position" Else MessageBox.Show("'CreatePosition' Variable on accepts the inputs: Create or Position.", _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 0 End If Else CreatePosition = "Create" End If If SharedVariable.Exists("BaseViewName") Then BaseViewName = SharedVariable("BaseViewName") SharedVariable.Remove("BaseViewName") Else BaseViewName = "TOP" End If If SharedVariable.Exists("WorkPointName") Then WorkPointName = SharedVariable("WorkPointName") SharedVariable.Remove("WorkPointName") Else WorkPointName = "Work Point1" End If If SharedVariable.Exists("DetailViewName") Then DetailViewName = SharedVariable("DetailViewName") SharedVariable.Remove("DetailViewName") Else DetailViewName = "A" End If If SharedVariable.Exists("DetailViewWScale") Then DetailViewWScale = SharedVariable("DetailViewWScale") SharedVariable.Remove("DetailViewWScale") Else DetailViewWScale = .375 End If If SharedVariable.Exists("DetailViewVerticalPos") Then DetailViewVerticalPos = SharedVariable("DetailViewVerticalPos") SharedVariable.Remove("DetailViewVerticalPos") Else DetailViewVerticalPos = 50 End If If SharedVariable.Exists("DetailViewHorizontalPos") Then DetailViewHorizontalPos = SharedVariable("DetailViewHorizontalPos") SharedVariable.Remove("DetailViewHorizontalPos") Else DetailViewHorizontalPos = 50 End If If SharedVariable.Exists("FenceSize") Then FenceSize = SharedVariable("FenceSize") SharedVariable.Remove("FenceSize") FenceSizeSet = True Else FenceSize = 2 FenceSizeSet = False End If If SharedVariable.Exists("FenceWidth") Then FenceWidth = SharedVariable("FenceWidth") SharedVariable.Remove("FenceWidth") Else FenceWidth = 2 End If If SharedVariable.Exists("FenceShape") Then FenceShape = SharedVariable("FenceShape") SharedVariable.Remove("FenceShape") If FenceShape = "Rect" ElseIf FenceShape = "Circ" Else MessageBox.Show("'FenceShape' Variable on accepts the inputs: Rect or Circ.", _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 0 End If Else FenceShape = "Rect" End If If SharedVariable.Exists("Debug") Then Debug = SharedVariable("Debug") SharedVariable.Remove("Debug") Else Debug = False End If '] Undo = ThisApplication.TransactionManager.StartTransaction(oDrawDoc, "Create or Position Detail View") '[Checks if named base view exists or if it is suppressed For Each oSheet In oDrawDoc.Sheets For Each oViewLooper In oSheet.DrawingViews If oViewLooper.Name = BaseViewName Then If oViewLooper.Suppressed = True Then GoTo 0 'Exits Rule End If oView = oViewLooper End If Next Next If oView Is Nothing Then MessageBox.Show("Cannot find base view named: " & BaseViewName, _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 0 'Exits Rule End If '] '[Sets sheet number And assembly document oSheet = oView.Parent oAssyDoc = oView.ReferencedDocumentDescriptor.ReferencedDocument '] '[Gets work point coordinates For Each oWP In oAssyDoc.ComponentDefinition.WorkPoints If oWP.Name = WorkPointName Then oSelectedWP = oWP End If Next If oSelectedWP Is Nothing MessageBox.Show("Cannot find work point named: " & WorkPointName, _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 0 'Exits Rule End If '] '[Gets Min and Max points for range box (opposite extents of visible assembly) oRangeBoxMin = oAssyDoc.ComponentDefinition.RangeBox.MinPoint oRangeBoxMax = oAssyDoc.ComponentDefinition.RangeBox.MaxPoint '] '[Gets Lengths of range box XRangeBox = oRangeBoxMax.X - oRangeBoxMin.X YRangeBox = oRangeBoxMax.Y - oRangeBoxMin.Y ZRangeBox = oRangeBoxMax.Z - oRangeBoxMin.Z '] '[Rereferenced work point to range box and scales them to drawing view. X3D = (oSelectedWP.Point.X - oRangeBoxMin.X) * oView.Scale Y3D = (oSelectedWP.Point.Y - oRangeBoxMin.Y) * oView.Scale Z3D = (oSelectedWP.Point.Z - oRangeBoxMin.Z) * oView.Scale '] '[Determines the orientation and roation of the base view. If oView.Camera.ViewOrientationType.ToString = "kArbitraryViewOrientation" oSheetTemp = oDrawDoc.Sheets.Add oViewTemp = oView.CopyTo(oSheetTemp) 1: If oViewTemp.Camera.ViewOrientationType.ToString <> "kArbitraryViewOrientation" BaseViewOrientation = oViewTemp.Camera.ViewOrientationType.ToString oViewTemp.Delete oSheetTemp.Delete oSheet.Activate ElseIf oViewTemp.Camera.ViewOrientationType.ToString = "kArbitraryViewOrientation" 'Sometime the rotate funtion fails, in which case an alternate method of rotating is used Try oViewTemp.RotateByAngle(90 * PI / 180) Catch oSS = oDrawDoc.SelectSet oSS.Clear oSS.Select(oViewTemp) oCD = ThisApplication.CommandManager.ControlDefinitions.Item("DrawingViewRotateCtxCmd") oSS.Select(oViewTemp) oCD.Execute2(False) AppActivate(ThisApplication.Caption) System.Windows.Forms.SendKeys.SendWait("{DOWN}^A90{TAB}{UP}{ENTER}") End Try RotateCounter = RotateCounter + 90 If RotateCounter > 270 Then MessageBox.Show("Something went wrong. Results may not be as intended.", _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 2 End If GoTo 1 End If ElseIf oView.Camera.ViewOrientationType.ToString = "kTopViewOrientation" BaseViewOrientation = oView.Camera.ViewOrientationType.ToString RotateCounter = 0 ElseIf oView.Camera.ViewOrientationType.ToString = "kBottomViewOrientation" BaseViewOrientation = oView.Camera.ViewOrientationType.ToString RotateCounter = 0 ElseIf oView.Camera.ViewOrientationType.ToString = "kFrontViewOrientation" BaseViewOrientation = oView.Camera.ViewOrientationType.ToString RotateCounter = 0 ElseIf oView.Camera.ViewOrientationType.ToString = "kBackViewOrientation" BaseViewOrientation = oView.Camera.ViewOrientationType.ToString RotateCounter = 0 ElseIf oView.Camera.ViewOrientationType.ToString = "kRightViewOrientation" BaseViewOrientation = oView.Camera.ViewOrientationType.ToString RotateCounter = 0 ElseIf oView.Camera.ViewOrientationType.ToString = "kLeftViewOrientation" BaseViewOrientation = oView.Camera.ViewOrientationType.ToString RotateCounter = 0 End If 2: '] 'RotateCounter, MinQuadrant '[Sets quadrant of min. range box and translates the model axis to the drawing view axis. If BaseViewOrientation = "kTopViewOrientation" And RotateCounter = 0 Then MinQuadrant = 2 X2D = X3D Y2D = -Z3D ElseIf BaseViewOrientation = "kBottomViewOrientation" And RotateCounter = 0 Then MinQuadrant = 3 X2D = X3D Y2D = Z3D ElseIf BaseViewOrientation = "kBottomViewOrientation" And RotateCounter = 180 Then MinQuadrant = 1 X2D = -X3D Y2D = -Z3D ElseIf BaseViewOrientation = "kFrontViewOrientation" And RotateCounter = 0 Then MinQuadrant = 3 X2D = X3D Y2D = Y3D ElseIf BaseViewOrientation = "kBackViewOrientation" And RotateCounter = 0 Then MinQuadrant = 4 X2D = -X3D Y2D = Y3D ElseIf BaseViewOrientation = "kBackViewOrientation" And RotateCounter = 180 Then MinQuadrant = 2 X2D = X3D Y2D = -Y3D ElseIf BaseViewOrientation = "kRightViewOrientation" And RotateCounter = 0 Then MinQuadrant = 4 X2D = -Z3D Y2D = Y3D ElseIf BaseViewOrientation = "kRightViewOrientation" And RotateCounter = 90 Then MinQuadrant = 1 X2D = -Y3D Y2D = -Z3D ElseIf BaseViewOrientation = "kLeftViewOrientation" And RotateCounter = 0 Then MinQuadrant = 3 X2D = Z3D Y2D = Y3D ElseIf BaseViewOrientation = "kLeftViewOrientation" And RotateCounter = 270 Then MinQuadrant = 2 X2D = Y3D Y2D = -Z3D ElseIf BaseViewOrientation = "kFrontViewOrientation" And RotateCounter = 90 Then MinQuadrant = 4 X2D = -Y3D Y2D = X3D ElseIf BaseViewOrientation = "kFrontViewOrientation" And RotateCounter = 270 Then MinQuadrant = 2 X2D = Y3D Y2D = -X3D Else MessageBox.Show("View orientation: " & BaseViewOrientation & " and roation: " & RotateCounter & _ " combination are not supported in this rule. Please add the combination to the rule." & _ " Refer to 'Create or Position Detail Rule 3D to 2D Calculator' in the iLogic Folder", _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 0 'Exits Rule End If '] '[Creates 2D point at drawing view corner associated with range box min. If MinQuadrant = 1 Then oViewOrigin = oTG.CreatePoint2d((oView.Position.X + oView.Width / 2), (oView.Position.Y + oView.Height / 2)) ElseIf MinQuadrant = 2 Then oViewOrigin = oTG.CreatePoint2d((oView.Position.X - oView.Width / 2), (oView.Position.Y + oView.Height / 2)) ElseIf MinQuadrant = 3 Then oViewOrigin = oTG.CreatePoint2d((oView.Position.X - oView.Width / 2), (oView.Position.Y - oView.Height / 2)) ElseIf MinQuadrant = 4 Then oViewOrigin = oTG.CreatePoint2d((oView.Position.X + oView.Width / 2), (oView.Position.Y - oView.Height / 2)) End If '] '[Checks for inconsistancies between rangebox and drawing detail view. If Debug = True Then If oView.Width = XRangeBox * oView.Scale Or oView.Width = YRangeBox * oView.Scale Or oView.Width = ZRangeBox * oView.Scale And _ oView.Height = XRangeBox * oView.Scale Or oView.Width = YRangeBox * oView.Scale Or oView.Width = ZRangeBox * oView.Scale Then 'MsgBox("Range box equals drawing view") Else MessageBox.Show("Range box does not equal drawing view. The detail fence will not be positioned correctly. This may be a result of " & _ "additional solids visible in the model that are not visible in the drawing; or the range box information is out of date.", _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) 'GoTo 0 'Exits Rule End If Else End If '] '[Creates 2D point at drawing view associated with work point. oViewWP = oTG.CreatePoint2d((oViewOrigin.X + X2D), (oViewOrigin.Y + Y2D)) '] '[Create or position detail view. Dim oDetailView As DetailDrawingView Dim DetailViewVerticalPerc As Double Dim DetailViewHorizontalPerc As Double 'Converts user percentage inputs to linear sheet distance DetailViewHorizontalPerc = DetailViewHorizontalPos/100 * oSheet.Width DetailViewVerticalPerc = DetailViewVerticalPos/100 * oSheet.Height oPointBase = oTG.CreatePoint2d(DetailViewHorizontalPerc, DetailViewVerticalPerc) oPointCorner1 = oTG.CreatePoint2d(oViewWP.X - (FenceWidth / 2), oViewWP.Y - (FenceSize / 2)) oPointCorner2 = oTG.CreatePoint2d(oViewWP.X + (FenceWidth / 2), oViewWP.Y + (FenceSize / 2)) 'Creates rectangular or circular detail view If CreatePosition = "Create" Then If FenceShape = "Rect" Then oDetailView = oSheet.DrawingViews.AddDetailView(oView, oPointBase, kFromBaseDrawingViewStyle, False, _ oPointCorner1, oPointCorner2, , DetailViewWScale, True, DetailViewName, ) ElseIf FenceShape = "Circ" Then oDetailView = oSheet.DrawingViews.AddDetailView(oView, oPointBase, kFromBaseDrawingViewStyle, True, _ oViewWP, FenceSize/2, , DetailViewWScale, True, DetailViewName, ) End If 'Positions existing detail view ElseIf CreatePosition = "Position" Then For Each oSheet In oDrawDoc.Sheets For Each oViewLooper In oSheet.DrawingViews If oViewLooper.Name = DetailViewName Then oDetailView = oViewLooper End If Next Next If oDetailView Is Nothing Then MessageBox.Show("Cannot find detail view named: " & DetailViewName, _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) GoTo 0 'Exits Rule End If If FenceShape = "Rect" Then If FenceSizeSet = False 'Gets current size of rect. fence. msgbox(oDetailView.Type.ToString) FenceWidth = Abs(oDetailView.FenceCornerTwo.X)-Abs(oDetailView.FenceCornerOne.X) FenceSize = Abs(oDetailView.FenceCornerTwo.Y) -Abs(oDetailView.FenceCornerOne.Y) End If 'Attached view warning Try If oDetailView.AttachPoint.Geometry Is Nothing Then Else oDetailView.AttachPoint = Nothing 'MsgBox("Attached") MsgBox(oDetailView.AttachPoint.Geometry.ToString) MessageBox.Show("View: " & oDetailView.Name & " should not be attached. Please detach it and try again.", _ "Create or Position Detail View", MessageBoxButtons.OK, MessageBoxIcon.Error) End If Catch 'MsgBox("Not Attached") End Try 'Relocates point to current size of rect. fence. oPointCorner1 = oTG.CreatePoint2d(oViewWP.X - (FenceWidth / 2), oViewWP.Y - (FenceSize / 2)) oPointCorner2 = oTG.CreatePoint2d(oViewWP.X + (FenceWidth / 2), oViewWP.Y + (FenceSize / 2)) 'Repositions corners of rect. fence. msgbox(oDetailView.AttachPoint.ToString) oDetailView.FenceCornerOne = oPointCorner1 oDetailView.FenceCornerTwo = oPointCorner2 ElseIf FenceShape = "Circ" Then oDetailView.FenceCenter = oViewWP If FenceSizeSet = True Then oDetailView.FenceRadius = FenceSize End If End If End If '] Undo.End 0 : '[ iLogic tracking log finish entry 'SharedVariable("RuleName") = "Drawing Parameter Control" 'SharedVariable("RulePrefix") = "Finish" 'iLogicVb.RunExternalRule("Application iLogic Tracking Log Entry") ']
Solved! Go to Solution.