Hi @zachri.jensen!!! The site dos not allow me to upload yet unfortunately ;(
Let me explain below:
a) The Python on the top is not working because I used Revit example, so I need to learn how to use Civil 3D interface:
import clr
Importar bibliotecas e referências dos Assemblies do AutoCAD
clr.AddReference(‘AcMgd’)
clr.AddReference(‘AcDbMgd’)
Importar bibliotecas e referências do arquivo de AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
doc = Application.DocumentManager.MdiActiveDocument
if IN[0]:
TransactionManager.Instance.EnsureInTransaction(doc) #Exemplo do Revit>>alterar para CIvil 3D
unit = doc.GetUnits()
format = FormatOptions(DisplayUnitType.DUT_METERS,0.0001) #Exemplo do Revit>>alterar para CIvil 3D
unit.SetFormatOptions(UnitType.UT_Length,format) #Exemplo do Revit>>alterar para CIvil 3D
doc.SetUnits(unit) #Exemplo do Revit>>alterar para CIvil 3D
TransactionManager.Instance.TransactionTaskDone() #Exemplo do Revit>>alterar para CIvil 3D
OUT = “Unidade de medida alterada para METRO e configurado 4 casas decimais”
else:
OUT = “Set IN[0] to true!”
b) The Python on the left is working only in current file, I need to add a float routine to read all dwg documents in a path right? I don’t know how to do it:
import clr
Add Assemblies for AutoCAD
clr.AddReference(‘AcMgd’)
clr.AddReference(‘AcDbMgd’)
Importar referências do arquivo de AutoCAD
from Autodesk.AutoCAD.ApplicationServices import *
from Autodesk.AutoCAD.DatabaseServices import *
from Autodesk.AutoCAD.Geometry import *
adoc = Application.DocumentManager.MdiActiveDocument #documento corrente>>Alterar para documento a ser escolhido pelo usuário
editor = adoc.Editor
def add_xref(path,blockName,switch):
global adoc
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
# Determinar se sobrepoe desenho existente ou insere
if switch==True:
oid = db.OverlayXref(path, blockName)
else:
oid = db.AttachXref(path, blockName)
if not oid.IsNull:
insPt = Point3d(IN[2],IN[3],IN[4])
# Create block reference
blkRef = BlockReference(insPt,oid)
# Add block table record
bt = t.GetObject(db.BlockTableId, OpenMode.ForWrite)
btr = t.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite)
btr.AppendEntity(blkRef);
t.AddNewlyCreatedDBObject(blkRef, True)
t.Commit()
return blkRef.Name
# IN[0]=local do documento
# IN[1]=documento.extensão
# IN[2]=string=origem=coordenada de referência atual
# IN[3]=string=origem=coordenada de referência atual
# IN[5]=string=origem=coordenada de referência atual
# IN[5]=verdadeiro ou falso
OUT = add_xref(IN[0],IN[1],IN[5])
c) The Python in the Right creates a Layer in current file, it is working, but I could not set this new layer to the Xref yet:
import clr
Importar referencias e bibliotecas dos Assemblies do AutoCAD e Civil 3D APIs
clr.AddReference(‘acmgd’)
clr.AddReference(‘acdbmgd’)
clr.AddReference(‘accoremgd’)
clr.AddReference(‘AecBaseMgd’)
clr.AddReference(‘AecPropDataMgd’)
clr.AddReference(‘AeccDbMgd’)
clr.AddReference(‘AeccPressurePipesMgd’)
clr.AddReference(‘acdbmgdbrep’)
clr.AddReference(‘System.Windows.Forms’)
Importar referencias e bibliotecas do standard Python references
import sys
sys.path.append(‘C:\Program Files (x86)\IronPython 2.7\Lib’)
import os
import math
Importar referencias e bibliotecas do manage arrays, collections and interact com usuário
from System import *
from System.IO import *
from System.Collections.Specialized import *
from System.Windows.Forms import MessageBox
Criar um alias do Autodesk.AutoCAD.ApplicationServices.Application class (Alias quer dizer “pseudônimo”, “apelido” e, em computação, é um comando que permite substituir uma palavra por outras ou por uma cadeia de caracteres)
import Autodesk.AutoCAD.ApplicationServices.Application as acapp
Importar referencias e bibliotecas do 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 *
from Autodesk.AutoCAD.Colors import Color
from Autodesk.AutoCAD.Colors import ColorMethod
Importar referencias e bibliotecas do PropertySets
from Autodesk.Aec.PropertyData import *
from Autodesk.Aec.PropertyData.DatabaseServices import *
Importar referencias e bibliotecas do Civil 3D
from Autodesk.Civil.ApplicationServices import *
from Autodesk.Civil.DatabaseServices import *
adoc = acapp.DocumentManager.MdiActiveDocument
ed = adoc.Editor
Exemplo da função
def create_layer(name, index):
indx = int(index)
# Se falhar
if not isinstance(name, str) or len(name) == 0:
raise Exception('The name is not a valid string')
if not isinstance(indx, int) or indx < 0 or indx > 255:
raise Exception('The index component is not a valid integer')
# Substituir caracteres especiais não permitido sno nome
name = name.replace(':', '_').replace(';', '_').replace(',', '_')
global adoc
result = False
with adoc.LockDocument():
with adoc.Database as db:
with db.TransactionManager.StartTransaction() as t:
# Definir o Layer Table Object
lt = t.GetObject(db.LayerTableId, OpenMode.ForRead)
# Checar se o layer já existe
if not lt.Has(name):
with LayerTableRecord() as ltr:
ltr = LayerTableRecord()
ltr.Name = name
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci,indx)
lt.UpgradeOpen()
lt.Add(ltr)
lt.DowngradeOpen()
t.AddNewlyCreatedDBObject(ltr, True)
else:
ltr = t.GetObject(lt[name], OpenMode.ForWrite)
# Definir cor
if ltr is not None:
ltr.Color = Color.FromColorIndex(ColorMethod.ByAci,indx)
result = True
t.Commit()
return result
if IN[0] == None or IN[1] == None:
OUT = create_layer.doc
else:
OUT = create_layer(IN[0], IN[1])
Thanks a lot!