Analytical opening creation throws ArgumentException
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello All
I'm getting ArgumentException when trying to create an analytical opening in a newly created panel. Document regeneration and separating out transactions doesn't appear to help.
I believe I have satisfied all of the requirements for the input CurveLoop as described in RevitAPI.chm under AnalyticalOpening.Create. Therefore I've included a sample macro to highlight the following:
CurveLoop for opening is planar
CurveLoop for opening is not self intersecting
CurveLoop for opening is located within the CurveLoop for the AnalyticalPanel the opening is to be associated with
CurveLoop is on same plane as that of CurveLoop for the AnalyticalPanel the opening is to be associated with
I've also reversed the direction of the opening CurveLoop using CurveLoop.Flip and by manually re-ordering the curves and curve direction to see if that helped but it didn't. Interestingly even when reversed the CurveLoop is always anticlockwise with the normal for the plane being reversed to maintain that. Seems impossible to create a clockwise CurveLoop or a discontinuous one via CurveLoop.Create or CurveLoop.Append.
I can't really understand why this exception above is being thrown. Seems the API can be a bit pedantic about these things compared to sketching similar in the UI.
Therefore please find code attached below and project document containing macro.
Imports System
Imports Autodesk.Revit.UI
Imports Autodesk.Revit.DB
Imports Autodesk.Revit.UI.Selection
Imports System.Collections.Generic
Imports System.Linq
Imports Autodesk.Revit.DB.[Structure]
Imports System.Diagnostics
<Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)> _
<Autodesk.Revit.DB.Macros.AddInId("47F465AE-B00B-4795-97E2-62B148427DDF")> _
Partial Public Class ThisDocument
Private Sub Module_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
End Sub
Private Sub Module_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
End Sub
Private Shared Function LN(ep0x As Double, ep0y As Double, ep0z As Double, ep1x As Double, ep1y As Double, ep1z As Double) As Line
Return Line.CreateBound(New XYZ(ep0x, ep0y, ep0z), New XYZ(ep1x, ep1y, ep1z))
End Function
Public Sub CreatePanel
Dim IntUIApp As UIApplication = Me.Application
Dim IntUIDoc As UIDocument = IntUIApp.ActiveUIDocument
Dim IntDoc As Document = IntUIDoc.Document
'Common X value to show curveloops are planar on YZ plane and share same plane.
Dim Xa As Double = -165.201660016252
'All loops are planar and anticlockwise
'Main outer loop
Dim LNSa As Curve() = New Curve(7) {}
LNSa(0) = LN(Xa, -124.167471493235, 11.4857251912482,
Xa, -91.3590725431041, 11.4857251912482)
LNSa(1) = LN(Xa, -91.3590725431041, 11.4857251912482,
Xa, -91.3590725431041, 0)
LNSa(2) = LN(Xa, -91.3590725431041, 0,
Xa, -109.860817750644, 0)
LNSa(3) = LN(Xa, -109.860817750644, 0,
Xa, -109.860817750644, 5.28189701052064)
LNSa(4) = LN(Xa, -109.860817750644, 5.28189701052064,
Xa, -114.453993603662, 5.28189701052064)
LNSa(5) = LN(Xa, -114.453993603662, 5.28189701052064,
Xa, -114.453993603662, 0)
LNSa(6) = LN(Xa, -114.453993603662, 0,
Xa, -124.167471493235, 0)
LNSa(7) = LN(Xa, -124.167471493235, 0,
Xa, -124.167471493235, 11.4857251912482)
'Inner loop with normal opposite to normal of outer loop
Dim LNSb As Curve() = New Curve(3) {}
LNSb(0) = LN(Xa, -96.2126418630068, 3.95242011869356,
Xa, -96.2126418630068, 8.54559597171193)
LNSb(1) = LN(Xa, -96.2126418630068, 8.54559597171193,
Xa, -100.805817716025, 8.54559597171193)
LNSb(2) = LN(Xa, -100.805817716025, 8.54559597171193,
Xa, -100.805817716025, 3.95242011869356)
LNSb(3) = LN(Xa, -100.805817716025, 3.95242011869356,
Xa, -96.2126418630068, 3.95242011869356)
'Inner loop with normal same as normal of outer loop
Dim LNSc As Curve() = New Curve(3) {}
LNSc(0) = LN(Xa, -96.2126418630068, 3.95242011869356,
Xa, -100.805817716025, 3.95242011869356)
LNSc(1) = LN(Xa, -100.805817716025, 3.95242011869356,
Xa, -100.805817716025, 8.54559597171193)
LNSc(2) = LN(Xa, -100.805817716025, 8.54559597171193,
Xa, -96.2126418630068, 8.54559597171193)
LNSc(3) = LN(Xa, -96.2126418630068, 8.54559597171193,
Xa, -96.2126418630068, 3.95242011869356)
Dim Cla As CurveLoop = CurveLoop.Create(LNSa.ToList)
Dim Clb As CurveLoop = CurveLoop.Create(LNSb.ToList)
Dim Clc As CurveLoop = CurveLoop.Create(LNSc.ToList)
Dim SB As New Text.StringBuilder
Try
Using Tx As New Transaction(IntDoc, "Panel with opening (opposite normal)")
If Tx.Start = TransactionStatus.Started Then
'This is ok
Dim AP As AnalyticalPanel = AnalyticalPanel.Create(IntDoc, Cla)
'This throws exception
AnalyticalOpening.Create(IntDoc, Clb, AP.Id)
Tx.Commit()
End If
End Using
Catch ex As Exception
SB.AppendLine(ex.Message)
'Debug.WriteLine(ex.Message)
End Try
Try
Using Tx As New Transaction(IntDoc, "Panel with opening (same normal)")
If Tx.Start = TransactionStatus.Started Then
'This is ok
Dim AP As AnalyticalPanel = AnalyticalPanel.Create(IntDoc, Cla)
'This throws exception
AnalyticalOpening.Create(IntDoc, Clc, AP.Id)
Tx.Commit()
End If
End Using
Catch ex As Exception
SB.AppendLine(ex.Message)
'Debug.WriteLine(ex.Message)
End Try
'Draw curves to show openings are within outer loop and share same plane.
Using Tx As New Transaction(IntDoc, "Draw")
If Tx.Start = TransactionStatus.Started Then
Dim PL As Plane = Cla.GetPlane
Dim SKP As SketchPlane = SketchPlane.Create(IntDoc, PL)
For Each item As Curve In Cla
IntDoc.Create.NewModelCurve(item, SKP)
Next
For Each item As Curve In Clb
IntDoc.Create.NewModelCurve(item, SKP)
Next
For Each item As Curve In Clc
IntDoc.Create.NewModelCurve(item, SKP)
Next
Tx.Commit()
End If
End Using
If SB.Length > 0 Then
TaskDialog.Show("Error",SB.ToString)
End If
End Sub
End Class
Model line result of running macro
On plan view with opening selected and top line of outer loop removed to show alignment
Developer Advocacy and Support +