AttributeError using Python Script

Hi,

I’m trying to get the style name but even though it appears as an option in dir(), I can’t use it.

Does anyone know if I’m forgetting something or doing something wrong?


Try
Out = test,dir(test.Name)

Or

Test= …
Teststy = test.Name

1 Like

Same thing.


And… same thing :confused:

2 picture
Delete. .Name from line 72

Just like the “Test”

Please Every time
you attach the code Not a picture of him
So that I can experiment to find the best solution If it is simple, for example, change faster

Line 73 Test.Name

Line 77 out= Teststy

# Load the Python Standard and DesignScript Libraries
import sys #sys is a fundamental Python library - here, we're using it to load in the standard IronPython libraries
import clr #This is .NET's Common Language Runtime. It's an execution environment that is able to execute code from several different languages.

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('ProtoGeometry') #A Dynamo library for its proxy geometry
#classes. You'll only need this if you're interacting with geometry
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('Civil3DNodes')
clr.AddReference('AutoCADNodes')

import Autodesk #Loads the Autodesk namespace
# Import references from AutoCAD
AAR = Autodesk.AutoCAD.Runtime
AAA = Autodesk.AutoCAD.ApplicationServices #Setting a handle to the currently-open instance of the AutoCAD application
AAD = Autodesk.AutoCAD.DatabaseServices
AAE = Autodesk.AutoCAD.EditorInput
AAG = Autodesk.AutoCAD.Geometry
AADy = Autodesk.AutoCAD.DynamoNodes

AUX = Autodesk.Aec.DatabaseServices

OP = AAD.OpenMode
TS = AAD.Transaction

# Import references from Civil3D
ACA = Autodesk.Civil.ApplicationServices #Setting a handle to the currently-open instance of the Civil3D application
ACD = Autodesk.Civil.DatabaseServices
ACDy = Autodesk.Civil.DynamoNodes

AD = ACA.CivilApplication.ActiveDocument #Finally, setting up handles to the active Civil3D document
AC = Autodesk.Civil

adoc = AAA.Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

#Inputs:
#IN[0] -> Civil Object
#IN[1] -> String 

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # E vem ai:

            Styles_doc = AD.Styles
            Styles_Ids = []
            PipeStyle_Ids = Styles_doc.PipeStyles
            StructureStyle_Ids = Styles_doc.StructureStyles
            Styles_Ids.append(PipeStyle_Ids)
            Styles_Ids.append(StructureStyle_Ids)
            
            Test = TS.GetObject(t,PipeStyle_Ids[0],OP.ForRead)
            #Teststy = Test.Name
            t.Commit()

# Assign your output to the OUT variable.
OUT = AD.Styles.PipeStyles, dir(AD.Styles.PipeStyles)

I just understand what’s happening, I read in the API that the “.Name” method is not to get, but to set.
image

1 Like

The problem was that Python did not accept two operations on the same line So must be divided to two lines

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # E vem ai:

            Styles_doc = AD.Styles
            Styles_Ids = []
            PipeStyle_Ids = Styles_doc.PipeStyles
            StructureStyle_Ids = Styles_doc.StructureStyles
            Styles_Ids.append(PipeStyle_Ids)
            Styles_Ids.append(StructureStyle_Ids)
            
            Test = TS.GetObject(t,PipeStyle_Ids[0],OP.ForRead)
            Teststy = Test.Name
            t.Commit()

# Assign your output to the OUT variable.
OUT = Teststy






As I said, the API says that this “.Name” in this type of object only serves to set the value and not get.

So I had to think of another way, arriving at this solution:

IN[1] is the string of the name of the style you are looking for.

And the output of the function is the style Id.

# Load the Python Standard and DesignScript Libraries
import sys #sys is a fundamental Python library - here, we're using it to load in the standard IronPython libraries
import clr #This is .NET's Common Language Runtime. It's an execution environment that is able to execute code from several different languages.

# Add Assemblies for AutoCAD and Civil3D
clr.AddReference('AcMgd')
clr.AddReference('AcCoreMgd')
clr.AddReference('AcDbMgd')
clr.AddReference('AecBaseMgd')
clr.AddReference('AecPropDataMgd')
clr.AddReference('AeccDbMgd')
clr.AddReference('ProtoGeometry') #A Dynamo library for its proxy geometry
#classes. You'll only need this if you're interacting with geometry
clr.AddReference('AeccPressurePipesMgd')
clr.AddReference('acdbmgdbrep')
clr.AddReference('Civil3DNodes')
clr.AddReference('AutoCADNodes')

import Autodesk #Loads the Autodesk namespace
# Import references from AutoCAD
AAR = Autodesk.AutoCAD.Runtime
AAA = Autodesk.AutoCAD.ApplicationServices #Setting a handle to the currently-open instance of the AutoCAD application
AAD = Autodesk.AutoCAD.DatabaseServices
AAE = Autodesk.AutoCAD.EditorInput
AAG = Autodesk.AutoCAD.Geometry
AADy = Autodesk.AutoCAD.DynamoNodes

AUX = Autodesk.Aec.DatabaseServices

OP = AAD.OpenMode
TS = AAD.Transaction

# Import references from Civil3D
ACA = Autodesk.Civil.ApplicationServices #Setting a handle to the currently-open instance of the Civil3D application
ACD = Autodesk.Civil.DatabaseServices
ACDy = Autodesk.Civil.DynamoNodes

AD = ACA.CivilApplication.ActiveDocument #Finally, setting up handles to the active Civil3D document
AC = Autodesk.Civil

adoc = AAA.Application.DocumentManager.MdiActiveDocument
editor = adoc.Editor

#Inputs:
#IN[0] -> Civil Object
#IN[1] -> String 

with adoc.LockDocument():
    with adoc.Database as db:

        with db.TransactionManager.StartTransaction() as t:
            # E vem ai:
            
            def GetIdByName(StyleName,StyleObject,StyleIds):
                #Função para pegar o Id do estilo pelo nome procurado
                #StyleName = Nome procurado
                #StyleObject = Lista de lista dos estilos
                #StyleIds = Lista de Ids dos estilos
                
                Style_Name = [] # Nomes dos estilos
                Id_Selected = [] # Id do estilo selecionado pelo nome
                for i in range(0,len(StyleObject)):               
                    for j in range(0,len(StyleObject[i])):
                        Style_Name = (ACD.DBObject.Name.GetValue(StyleObject[i][j]))
                        if Style_Name.Equals(StyleName):
                             Id_Selected = StyleIds[i][j]
                return Id_Selected
            
            Styles_doc = AD.Styles # Estilos do documento
            Styles_Ids = [] # Id dos estilos
            PipeStyle_Ids = Styles_doc.PipeStyles # Id dos Pipe Styles
            StructureStyle_Ids = Styles_doc.StructureStyles #Id dos Structures Styles
            Styles_Ids.append(PipeStyle_Ids)
            Styles_Ids.append(StructureStyle_Ids)
            
            Style_Object =[] # Lista de estilos em "Autodesk.Civil.DatabaseServices.Style.PipeStyles"
            Style_Aux = [] # Variável auxiliar
            for i in range(0,len(Styles_Ids)):
                Style_Aux = []
                for j in range(0,len(list(Styles_Ids[i]))):
                    Style_Aux.append(TS.GetObject(t,Styles_Ids[i][j],OP.ForRead)) #Pegando o estilo em "Autodesk.Civil.DatabaseServices.Style.PipeStyles"               
                Style_Object.append(Style_Aux)
                
            Id = GetIdByName(IN[1],Style_Object,Styles_Ids) # Pegando o estilo selecionado pelo nome 
            #ToConfirm = ACD.DBObject.Name.GetValue(TS.GetObject(t,GetIdByName(IN[1],Style_Object,Styles_Ids),OP.ForRead))  

            t.Commit()

# Assign your output to the OUT variable.
OUT = GetIdByName(IN[1],Style_Object,Styles_Ids)

1 Like