- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Using second array takes the values from the first array.
Hello All,
I have been able to put together a bit of code which lets me dimension a number of holes regardless of the order in which they are placed. This works great but im having a problem when I try to add this for a second time in the same rule.
First I set up the rule and the Workpoints for holes and faces for the edges.
'Initial setup
'References this document
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document
'References this drawing sheet
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
'References this drawing view
Dim oView As DrawingView
oView = ActiveSheet.View("VIEW2").View
'References this drawing view Model
Dim oAssyDoc As AssemblyDocument
oAssyDoc = ActiveSheet.View("VIEW2").ModelDocument
'Readys code for creation of reference points for dimension placement
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
'Readys code for creation of general dimensions
Dim oGeneralDims As GeneralDimensions
oGeneralDims = oSheet.DrawingDimensions.GeneralDimensions
Dim oDoc As Document = oView.ReferencedDocumentDescriptor.ReferencedDocument
'Dimension Style:
Dim oDimStyle As DimensionStyle
Dim oStylesMgr As DrawingStylesManager = oDrawDoc.StylesManager
oDimStyle = oStylesMgr.DimensionStyles.Item("iLogic")
Dim oGeom1 As Inventor.GeometryIntent
Dim oWP101 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("Gat1")
Dim oCenterMark101 As Inventor.Centermark
If Aantal_gaten > 0 Then
oView.SetIncludeStatus(oWP101, True)
oCenterMark101 = oSheet.Centermarks.AddByWorkFeature(oWP101, oView)
oGeom1 = oSheet.CreateGeometryIntent(oCenterMark101, kPoint2dIntent)
oCenterMark101.Visible = False
End If
Dim oGeom2 As Inventor.GeometryIntent
Dim oWP102 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("Gat2")
Dim oCenterMark102 As Inventor.Centermark
If Aantal_gaten > 1 Then
oView.SetIncludeStatus(oWP102, True)
oCenterMark102 = oSheet.Centermarks.AddByWorkFeature(oWP102, oView)
oGeom2 = oSheet.CreateGeometryIntent(oCenterMark102, kPoint2dIntent)
oCenterMark102.Visible = False
End If
Dim oGeom3 As Inventor.GeometryIntent
Dim oWP103 As Inventor.WorkPoint = oDoc.ComponentDefinition.WorkPoints.Item("Gat3")
Dim oCenterMark103 As Inventor.Centermark
If Aantal_gaten > 2 Then
oView.SetIncludeStatus(oWP103, True)
oCenterMark103 = oSheet.Centermarks.AddByWorkFeature(oWP103, oView)
oGeom3 = oSheet.CreateGeometryIntent(oCenterMark103, kPoint2dIntent)
oCenterMark103.Visible = False
End If
'Etc............... (x20)
oObjs = oAssyDoc.AttributeManager.FindObjects("RH_links","RH_links","1")
aoEdge01 = oObjs.Item(1)
oObjs = oAssyDoc.AttributeManager.FindObjects("RH_rechts","RH_rechts","1")
aoEdge02 = oObjs.Item(1)
oDrawViewCurves = oView.DrawingCurves(aoEdge01)
aoDrawCurves01 = oDrawViewCurves.Item(1)
oDrawViewCurves = oView.DrawingCurves(aoEdge02)
aoDrawCurves02 = oDrawViewCurves.Item(1)Then I place the holes from smallest to biggest and create dimensions between The edges and all the holes.
Dim oArray As New ArrayList
Dim i As Integer
Dim oG(0 To 19) As Inventor.GeometryIntent
'[Sorteer gaten
Dim oGatB(0 To 19) As Double
oGatB(0) = B1
oGatB(1) = B2
oGatB(2) = B3
oGatB(3) = B4
oGatB(4) = B5
oGatB(5) = B6
oGatB(6) = B7
oGatB(7) = B8
oGatB(8) = B9
oGatB(9) = B10
oGatB(10) = B11
oGatB(11) = B12
oGatB(12) = B13
oGatB(13) = B14
oGatB(14) = B15
oGatB(15) = B16
oGatB(16) = B17
oGatB(17) = B18
oGatB(18) = B19
oGatB(19) = B20
For i = 0 To 19 Step 1
If Aantal_gaten > i Then
oArray.Add(oGatB(i))
End If
Next
oArray.Sort()
']
'[Plaats maatvoering vanaf de linker rand naar het eerste gat
Select Case oArray(0)
Case B1
oG0 = oGeom1
Case B2
oG0 = oGeom2
Case B3
oG0 = oGeom3
Case B4
oG0 = oGeom4
Case B5
oG0 = oGeom5
Case B6
oG0 = oGeom6
Case B7
oG0 = oGeom7
Case B8
oG0 = oGeom8
Case B9
oG0 = oGeom9
Case B10
oG0 = oGeom10
Case B11
oG0 = oGeom11
Case B12
oG0 = oGeom12
Case B13
oG0 = oGeom13
Case B14
oG0 = oGeom14
Case B15
oG0 = oGeom15
Case B16
oG0 = oGeom16
Case B17
oG0 = oGeom17
Case B18
oG0 = oGeom18
Case B19
oG0 = oGeom19
Case B20
oG0 = oGeom20
End Select
oPt = oTG.CreatePoint2d(oView.Left + (oView.Width / 2), oView.Top - oView.Height - 1.5)
oDim = oGeneralDims.AddLinear(oPt, oSheet.CreateGeometryIntent(aoDrawCurves01), oG0, DimensionTypeEnum.kHorizontalDimensionType)
oDim.Style = oDimStyle
oDimAtt = oDim.AttributeSets.Add("iLogic_Created")
oStart = oG0
']
'[Plaats maatvoering tussen gaten
For i = 1 To oArray.Count - 1 Step 1
Select Case oArray(i)
Case B1
oG(i) = oGeom1
Case B2
oG(i) = oGeom2
Case B3
oG(i) = oGeom3
Case B4
oG(i) = oGeom4
Case B5
oG(i) = oGeom5
Case B6
oG(i) = oGeom6
Case B7
oG(i) = oGeom7
Case B8
oG(i) = oGeom8
Case B9
oG(i) = oGeom9
Case B10
oG(i) = oGeom10
Case B11
oG(i) = oGeom11
Case B12
oG(i) = oGeom12
Case B13
oG(i) = oGeom13
Case B14
oG(i) = oGeom14
Case B15
oG(i) = oGeom15
Case B16
oG(i) = oGeom16
Case B17
oG(i) = oGeom17
Case B18
oG(i) = oGeom18
Case B19
oG(i) = oGeom19
Case B20
oG(i) = oGeom20
End Select
If oArray(i) <> oArray(i - 1) Then
oDim = oGeneralDims.AddLinear(oPt, oStart, oG(i), DimensionTypeEnum.kHorizontalDimensionType)
oDim.Style = oDimStyle
oDimAtt = oDim.AttributeSets.Add("iLogic_Created")
oStart = oG(i)
End If
'MsgBox(oArray(i).ToString)
Next
']
'Plaats de maatvoering van het laatste gat naar de rechter rand
oDim = oGeneralDims.AddLinear(oPt, oSheet.CreateGeometryIntent(aoDrawCurves02), oStart, DimensionTypeEnum.kHorizontalDimensionType)
oDim.Style = oDimStyle
oDimAtt = oDim.AttributeSets.Add("iLogic_Created")No problem so far, but now i want to not only dimension the width but also the height. So I copy and paste the last part and change all the needed variables to get the following.
'[Sorteer gaten
Dim oGatH(0 To 19) As Double
oGatH(0) = H1
oGatH(1) = H2
oGatH(2) = H3
oGatH(3) = H4
oGatH(4) = H5
oGatH(5) = H6
oGatH(6) = H7
oGatH(7) = H8
oGatH(8) = H9
oGatH(9) = H10
oGatH(10) = H11
oGatH(11) = H12
oGatH(12) = H13
oGatH(13) = H14
oGatH(14) = H15
oGatH(15) = H16
oGatH(16) = H17
oGatH(17) = H18
oGatH(18) = H19
oGatH(19) = H20
For i = 0 To 19 Step 1
If Aantal_gaten > i Then
oArray.Add(oGatH(i))
End If
Next
']
'[Plaats maatvoering naar eerste gat
Select Case oArray(0)
Case H1
oG0 = oGeom1
Case H2
oG0 = oGeom2
Case H3
oG0 = oGeom3
Case H4
oG0 = oGeom4
Case H5
oG0 = oGeom5
Case H6
oG0 = oGeom6
Case H7
oG0 = oGeom7
Case H8
oG0 = oGeom8
Case H9
oG0 = oGeom9
Case H10
oG0 = oGeom10
Case H11
oG0 = oGeom11
Case H12
oG0 = oGeom12
Case H13
oG0 = oGeom13
Case H14
oG0 = oGeom14
Case H15
oG0 = oGeom15
Case H16
oG0 = oGeom16
Case H17
oG0 = oGeom17
Case H18
oG0 = oGeom18
Case H19
oG0 = oGeom19
Case H20
oG0 = oGeom20
End Select
oPt = oTG.CreatePoint2d(oView.Left + oView.Width + 1.5, oView.Top - (oView.Height / 2))
oDim = oGeneralDims.AddLinear(oPt, oSheet.CreateGeometryIntent(aoDrawCurves01), oG0, DimensionTypeEnum.kVerticalDimensionType)
oDim.Style = oDimStyle
oDimAtt = oDim.AttributeSets.Add("iLogic_Created")
oStart = oG0
']
'[Plaats maatvoering tussen gaten
Dim oG(0 To 19) As Inventor.GeometryIntent
For i = 1 To oArray.Count - 1 Step 1
Select Case oArray(i)
Case H1
oG(i) = oGeom1
Case H2
oG(i) = oGeom2
Case H3
oG(i) = oGeom3
Case H4
oG(i) = oGeom4
Case H5
oG(i) = oGeom5
Case H6
oG(i) = oGeom6
Case H7
oG(i) = oGeom7
Case H8
oG(i) = oGeom8
Case H9
oG(i) = oGeom9
Case H10
oG(i) = oGeom10
Case H11
oG(i) = oGeom11
Case H12
oG(i) = oGeom12
Case H13
oG(i) = oGeom13
Case H14
oG(i) = oGeom14
Case H15
oG(i) = oGeom15
Case H16
oG(i) = oGeom16
Case H17
oG(i) = oGeom17
Case H18
oG(i) = oGeom18
Case H19
oG(i) = oGeom19
Case H20
oG(i) = oGeom20
End Select
If oArray(i) <> oArray(i - 1) Then
oDim = oGeneralDims.AddLinear(oPt, oStart, oG(i), DimensionTypeEnum.kVerticalDimensionType)
oDim.Style = oDimStyle
oDimAtt = oDim.AttributeSets.Add("iLogic_Created")
oStart = oG(i)
End If
']
Next
oDim = oGeneralDims.AddLinear(oPt, oSheet.CreateGeometryIntent(aoDrawCurves02), oStart, DimensionTypeEnum.kVerticalDimensionType)
oDim.Style = oDimStyle
oDimAtt = oDim.AttributeSets.Add("iLogic_Created")
']I think I have changed everything I need to change in this second part to be able to but this ends up happening and I receive an error.
When I check what is happening with a messagebox it seems like after the first correctly used hole in the array it takes the second and all following holes from the first array.
This is not a big probelem since I have been able to just put them in two seperate rules and make it work but it would be nice to know a way to get them both to be in the same rule and functioning in the future.
Thanks in advance,
Jeffrey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
That's a pretty long and complicated looking rule. It's probably not getting much attention, because it's probably a little more than most folks here in the forum want to dive into to debug for you without having the actual files to play with, and perhaps a little more info.
If I were you, I would leave it in two seperate rules to help simplify it, but at the end of the first rule, just use the following line, and just replace the SecondRuleName, with the name of your second rule.
iLogicVb.RunRule("SecondRuleName")
or
iLogicVb.RunExternalRule("SecondRuleName")This method does have some advantages.
I do this a lot, because there are certain functions & strings of code that I use in many different places, and this allows me to have just one copy of that code, in one place, instead of various versions of it accross many different rules. And if something needs to change, I can fix it in that one location instead of many.
I hope this helps.
Wesley Crihfield
(Not an Autodesk Employee)