DynamoDS / Dynamo

Open Source Graphical Programming for Design
https://dynamobim.org
Other
1.74k stars 634 forks source link

Unhandled exception when using the cdoc.Styles.SurfaceStyles property in Dynamo for Civil 3D 2022 and 2023 #13771

Closed Snofres closed 1 year ago

Snofres commented 1 year ago

Issue Description

Please fill in the following information to help us reproduce the issue: I can't call a surface style with it's name or by element index in list in cdoc.Styles.SurfaceStyles when using Python Script. This produces an unhandled exception and error message in the Python node. The drawing contains a Surface Style with name "Standard", but I can't call this in the Python Node in Dynamo, neither by name "Standard" or by index, e.g. styleId = cdoc.Styles.SurfaceStyles[3]. Creating a TIN-surface with e.g. surfaceId = TinSurface.Create(surfaceName, styleName) produces the same error, when styleName is an existing style, e.g "Standard" or cdoc.Styles.SurfaceStyles[x]. Creating a TIN-surface with this method is successfull when a new surface style is created in the same script, e.g with styleId = cdoc.Styles.SurfaceStyles.Add("example style")

Dynamo version

Dynamo: 2.15.1.6076

Operating system

OS: Microsoft Windows NT 10.0.19044.0

What did you do?

Load the Python Standard and DesignScript Libraries

import sys import clr

Add Assemblies for AutoCAD and Civil3D

clr.AddReference('AcMgd') clr.AddReference('AcCoreMgd') clr.AddReference('AcDbMgd') clr.AddReference('AecBaseMgd') clr.AddReference('AecPropDataMgd') clr.AddReference('AeccDbMgd')

Import references from AutoCAD

from Autodesk.AutoCAD.Runtime import from Autodesk.AutoCAD.ApplicationServices import from Autodesk.AutoCAD.EditorInput import from Autodesk.AutoCAD.DatabaseServices import from Autodesk.AutoCAD.Geometry import *

Import references from Civil3D

from Autodesk.Civil.ApplicationServices import from Autodesk.Civil.DatabaseServices import

The inputs to this node will be stored as a list in the IN variables.

adoc = Application.DocumentManager.MdiActiveDocument editor = adoc.Editor styleId=[] with adoc.LockDocument(): with adoc.Database as db:

    with db.TransactionManager.StartTransaction() as t:
        cdoc = CivilApplication.ActiveDocument
        # Select a Surface style
        #styleId = cdoc.Styles.SurfaceStyles.Contains("Standard")
        styleId = cdoc.Styles.SurfaceStyles["Standard"]
        #styleId = cdoc.Styles.SurfaceStyles[0]
        t.Commit()
        pass

Assign your output to the OUT variable.

OUT = styleId

What did you expect to see?

I exected the node to output the Surface Style

What did you see instead?

2023-02-25_17-25-09 2023-02-25_17-25-25 2023-02-25_17-25-52 2023-02-25_17-26-20

typeerror no method matches given arguments for OnExit. Unhandled exeption:

Application does not support just-in-time (JIT) debugging. See the end of this message for details.

** Exception Text ** System.InvalidOperationException: Operation is not valid due to the current state of the object. at Autodesk.AutoCAD.DatabaseServices.Transaction.CheckTopTransaction() at Autodesk.AutoCAD.DatabaseServices.Transaction.GetObject(ObjectId id, OpenMode mode) at Autodesk.AutoCAD.DynamoApp.Services.TraceData.RemoveTraceDataFromDocumentByBindingNodeIds(IEnumerable1 guids) at Autodesk.AutoCAD.DynamoApp.Services.TraceData.SaveTraceDataToDocument(HomeWorkspaceModel hws) at Autodesk.AutoCAD.DynamoApp.AcDynamoModel.OnRefreshCompleted(Object sender, EvaluationCompletedEventArgs e) at System.EventHandler1.Invoke(Object sender, TEventArgs e) at Dynamo.Graph.Workspaces.HomeWorkspaceModel.OnRefreshCompleted(EvaluationCompletedEventArgs e) at Dynamo.Scheduler.AsyncTaskExtensions.<>c__DisplayClass3_0.b_1(AsyncTask ) at Dynamo.Scheduler.AsyncTaskCompletedHandler.Invoke(AsyncTask asyncTask) at Dynamo.Scheduler.AsyncTask.HandleTaskCompletion() at Dynamo.Scheduler.DynamoScheduler.ProcessTaskInternal(AsyncTask asyncTask) at Dynamo.Scheduler.DynamoScheduler.ProcessNextTask(Boolean waitIfTaskQueueIsEmpty) at Autodesk.AutoCAD.DynamoApp.SchedulerThread.ExecuteInApplicationContextCallback(Object userData) at myCallback(Void* data) at Autodesk.AutoCAD.ApplicationServices.DocumentCollection.ExecuteInApplicationContext(ExecuteInApplicationContextCallback callback, Object data) at System.EventHandler.Invoke(Object sender, EventArgs e) at Autodesk.AutoCAD.ApplicationServices.Core.Application.raise_Idle(Object value0, EventArgs value1) at Autodesk.AutoCAD.ApplicationServices.Core.Application.OnIdle()

What packages or external references (if any) were used?

None

Stack Trace

(From the Dynamo crash window select 'Details' -> 'Copy' and paste here)

CLR: 4.0.30319.42000

github-actions[bot] commented 1 year ago

Thank you for submitting the issue to us. We are sorry to see you get stuck with your workflow. While waiting for our team member to respond, please feel free to browse our forum at https://forum.dynamobim.com/ for more Dynamo related information.

Snofres commented 1 year ago

Updated with further info.

Snofres commented 1 year ago

It's obviously a known issue for Python.Net that it doensn't handle collection[index]. This thread shows a solution: https://forum.dynamobim.com/t/civil3d-api-python3-syntax-error/79426

As a workaround this syntax can be used instead: styleId = cdoc.Styles.SurfaceStyles.get_Item("Standard")

QilongTang commented 1 year ago

@Snofres We appreciate the additional information you added here for other users. Glad you were able to address this.