Message 1 of 5
Error Deleting Workplanes
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm having some issues with the code below, it doesn't allow me to delete the workplanes before creating new ones, and it only fails in certain circumstances which doesn't seem relevant at all. The error is on the code "oWPlane.Delete". Please help.
Error on line 14 in rule: Work Plane Creation (indi.), in document: assembly.iam
Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL))
Sub Main oDef = ThisDoc.Document.ComponentDefinition Dim oWPlane As WorkPlane oSurfaces = oDef.WorkPlanes Dim name As String For Each oWPlane In oSurfaces name = oWPlane.Name If Left(name, 3) = "dim" oWPlane.Delete End If Next myDoubleValues = New Double() {x1, y1, x2, y2, x3, y3, x4, y4, x5, y5, x6, y6, x7, y7, x8, y8, x9, y9, x10, y10, x11, y11, x12, y12 } Dim arrayAnchorX(anchorBoltNo - 1) As Double Dim arrayAnchorY(anchorBoltNo - 1) As Double For i = 0 To anchorBoltNo - 1 arrayAnchorX(i) = myDoubleValues(i * 2) arrayAnchorY(i) = myDoubleValues(i * 2 + 1) Next Dim arrayAnchorUniqueX(0) As Double Dim arrayAnchorUniqueY(0) As Double arrayAnchorUniqueX(0) = arrayAnchorX(0) arrayAnchorUniqueY(0) = arrayAnchorY(0) 'Delete all the duplicate dimension For i = 1 To anchorBoltNo - 1 If Not arrayAnchorUniqueX.Contains(arrayAnchorX(i)) Then Array.Resize(arrayAnchorUniqueX, arrayAnchorUniqueX.Length + 1) arrayAnchorUniqueX(arrayAnchorUniqueX.Length - 1) = arrayAnchorX(i) End If If Not arrayAnchorUniqueY.Contains(arrayAnchorY(i)) Then Array.Resize(arrayAnchorUniqueY, arrayAnchorUniqueY.Length + 1) arrayAnchorUniqueY(arrayAnchorUniqueY.Length - 1) = arrayAnchorY(i) End If Next Array.Sort(arrayAnchorUniqueX) Array.Sort(arrayAnchorUniqueY) anchorDimQtyX = arrayAnchorUniqueX.Length anchorDimQtyY = arrayAnchorUniqueY.Length For i = 0 To arrayAnchorUniqueY.Length - 1 oWPlane = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("XY Plane"), -arrayAnchorUniqueY(i)) oWPlane.Name = "dimPlaneXY" & i 'oWPlane.Visible = False Next For i = 0 To arrayAnchorUniqueX.Length - 1 oWPlane = AddWorkPlaneInAssemblyOffset(oDef.WorkPlanes("YZ Plane"), arrayAnchorUniqueX(i)) oWPlane.Name = "dimPlaneYZ" & i 'oWplane.Visible = False Next End Sub Function AddWorkPlaneInAssemblyOffset(oFace As Object, oOffset As Double) As WorkPlane Dim uOM As UnitsOfMeasure = ThisDoc.Document.UnitsOfMeasure Dim oAsm As AssemblyDocument = ThisApplication.ActiveDocument Dim oDef As AssemblyComponentDefinition = oAsm.ComponentDefinition Dim oOriginPnt As Point Dim oXaxis As UnitVector Dim oYaxis As UnitVector oOriginPnt = ThisApplication.TransientGeometry.CreatePoint(0#, 0#, 0#) oXaxis = ThisApplication.TransientGeometry.CreateUnitVector(1#, 0#, 0#) oYaxis = ThisApplication.TransientGeometry.CreateUnitVector(0#, 1#, 0#) Dim oPlane As WorkPlane = oDef.WorkPlanes.AddFixed(oOriginPnt, oXaxis, oYaxis) oPlane.AutoResize = True oDef.Constraints.AddFlushConstraint(oFace, oPlane, uOM.ConvertUnits(oOffset, uOM.LengthUnits, UnitsTypeEnum.kDatabaseLengthUnits)) oPlane.AutoResize = False Return oPlane End Function