viktor.external.autocad
AutoCADConnection
- class viktor.external.autocad.autocad.AutoCADConnection(session)
Bases:
_AutoCADConnectionNew in 14.35.0The
acadobject returned byconnect()orattach(), used to control AutoCAD through its ActiveX Automation API. Each call returns the API result, or[*out_params, ret]when the call has output parameters. Objects returned by calls come back as opaque session-scoped handles, usable in further calls and as arguments; a property is read with call syntax (line.Length()) and written by plain assignment (line.Layer = "STRUCTURE").Some members are refused by the worker for security and session safety (raising
viktor.errors.ExecutionError), and filename arguments are confined to the session’s working directory: save withSaveAsand a relative filename.
attach
- viktor.external.autocad.autocad.attach(timeout=60)
- New in 14.35.0
Attach to the AutoCAD instance already running on the worker machine and control it through the AutoCAD ActiveX Automation API, like
connect(), but without starting a fresh instance. Typical use: a personal worker on the engineer’s own machine, so the app acts on the drawing they have open on screen.Warning
This is a BETA feature.
Requires a worker of kind
autocad. Declare it in your viktor.config.toml:worker_integrations = [ "autocad", ]Usage:
import viktor as vkt with vkt.autocad.attach(timeout=60) as acad: layer = acad.ActiveDocument.ActiveLayer.Name() # reads the drawing open in AutoCAD acad.ActiveDocument.Regen(0) # changes show in the user's windowClosing the session detaches without exiting the instance. The app can change the attached drawing but not save it in place: saving requires
SaveAswith a relative filename, which writes into the session directory.Note
The ActiveX members you call on
acad(e.g.acad.ActiveDocument.ModelSpace.AddLine) mirror the AutoCAD Object Model and are not listed here. Look them up in the AutoCAD ActiveX Reference Guide on Autodesk’s developer documentation, or in theacadauto.chmhelp file in your AutoCAD installation directory.- Parameters:
timeout (
int) – per-call timeout in seconds; also bounds the attach itself, so keep it at or above the platform’s 30 second bind window.- Return type:
Exceptions which can be raised during execution:
viktor.errors.WorkerSessionAttachError: the attach failed, e.g. no AutoCAD is running on the worker machine.reasonnames the cause; that set is open.viktor.errors.ExecutionError: generic error during a call. Error message provides more information.viktor.errors.WorkerSessionError: the session was lost after attaching (e.g. the user closed the AutoCAD instance). The session cannot be resumed; start a new one to continue.TimeoutError: a call took longer than
timeout
connect
- viktor.external.autocad.autocad.connect(timeout=60)
- New in 14.35.0
Connect to AutoCAD running on a connected VIKTOR worker and control it through the AutoCAD ActiveX Automation API directly from your app, as shown below. Always starts a fresh instance: if AutoCAD is already open on the worker machine the session is refused — close it there, or use
attach()to act on it.Warning
This is a BETA feature.
Requires a worker of kind
autocad. Declare it in your viktor.config.toml:worker_integrations = [ "autocad", ]Usage:
import viktor as vkt with vkt.autocad.connect(timeout=60) as acad: ms = acad.ActiveDocument.ModelSpace line = ms.AddLine([0, 0, 0], [6, 0, 0]) # returns a session-scoped object handle line.Layer = "STRUCTURE" # property write: plain assignment length = line.Length() # property read: call syntax (note the parens) acad.ActiveDocument.SaveAs("beam.dwg") # use a relative filename, not an absolute pathNote
The ActiveX members you call on
acad(e.g.acad.ActiveDocument.ModelSpace.AddLine) mirror the AutoCAD Object Model and are not listed here. Look them up in the AutoCAD ActiveX Reference Guide on Autodesk’s developer documentation, or in theacadauto.chmhelp file in your AutoCAD installation directory.- Parameters:
timeout (
int) – per-call timeout in seconds. Opening the session waits for AutoCAD to be ready, so it must also cover starting AutoCAD up on the worker.- Return type:
Exceptions which can be raised during execution:
viktor.errors.ExecutionError: generic error. Error message provides more information. A host whose AutoCAD license is not activated also fails this way: AutoCAD blocks on an interactive sign-in dialog that the worker cannot answer, so starting it up times out.viktor.errors.WorkerSessionError: the session was lost (e.g. its AutoCAD instance was torn down). The session cannot be resumed; start a new one to continue.TimeoutError: a call took longer than
timeout
AutoCAD enum values, generated from AutoCAD 26.0s (LMS Tech).
Ac3DPolylineType
AcARXDemandLoad
AcActiveSpace
AcAlignment
- class viktor.external.autocad.enums.AcAlignment(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcAlignmentvalues, mirroring the product API’s names so code reads like its docs.- acAlignmentAligned = 3
- acAlignmentBottomCenter = 13
- acAlignmentBottomLeft = 12
- acAlignmentBottomRight = 14
- acAlignmentCenter = 1
- acAlignmentFit = 5
- acAlignmentLeft = 0
- acAlignmentMiddle = 4
- acAlignmentMiddleCenter = 10
- acAlignmentMiddleLeft = 9
- acAlignmentMiddleRight = 11
- acAlignmentRight = 2
- acAlignmentTopCenter = 7
- acAlignmentTopLeft = 6
- acAlignmentTopRight = 8
AcAlignmentPointAcquisition
AcAngleUnits
AcAttachmentPoint
- class viktor.external.autocad.enums.AcAttachmentPoint(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcAttachmentPointvalues, mirroring the product API’s names so code reads like its docs.- acAttachmentPointBottomCenter = 8
- acAttachmentPointBottomLeft = 7
- acAttachmentPointBottomRight = 9
- acAttachmentPointMiddleCenter = 5
- acAttachmentPointMiddleLeft = 4
- acAttachmentPointMiddleRight = 6
- acAttachmentPointTopCenter = 2
- acAttachmentPointTopLeft = 1
- acAttachmentPointTopRight = 3
AcAttributeMode
- class viktor.external.autocad.enums.AcAttributeMode(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcAttributeModevalues, mirroring the product API’s names so code reads like its docs.- acAttributeModeConstant = 2
- acAttributeModeInvisible = 1
- acAttributeModeLockPosition = 16
- acAttributeModeMultipleLine = 32
- acAttributeModeNormal = 0
- acAttributeModePreset = 8
- acAttributeModeVerify = 4
AcBlockConnectionType
AcBlockScaling
AcBoolean
AcBooleanType
AcCellAlignment
- class viktor.external.autocad.enums.AcCellAlignment(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcCellAlignmentvalues, mirroring the product API’s names so code reads like its docs.- acBottomCenter = 8
- acBottomLeft = 7
- acBottomRight = 9
- acMiddleCenter = 5
- acMiddleLeft = 4
- acMiddleRight = 6
- acTopCenter = 2
- acTopLeft = 1
- acTopRight = 3
AcCellContentLayout
- class viktor.external.autocad.enums.AcCellContentLayout(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcCellContentLayoutvalues, mirroring the product API’s names so code reads like its docs.- acCellContentLayoutFlow = 1
- acCellContentLayoutStackedHorizontal = 2
- acCellContentLayoutStackedVertical = 4
AcCellContentType
- class viktor.external.autocad.enums.AcCellContentType(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcCellContentTypevalues, mirroring the product API’s names so code reads like its docs.- acCellContentTypeBlock = 4
- acCellContentTypeField = 2
- acCellContentTypeUnknown = 0
- acCellContentTypeValue = 1
AcCellEdgeMask
AcCellMargin
- class viktor.external.autocad.enums.AcCellMargin(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcCellMarginvalues, mirroring the product API’s names so code reads like its docs.- acCellMarginBottom = 4
- acCellMarginHorzSpacing = 16
- acCellMarginLeft = 2
- acCellMarginRight = 8
- acCellMarginTop = 1
- acCellMarginVertSpacing = 32
AcCellOption
AcCellProperty
- class viktor.external.autocad.enums.AcCellProperty(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcCellPropertyvalues, mirroring the product API’s names so code reads like its docs.- acAlignmentProperty = 32
- acAllCellProperties = 524287
- acAutoScale = 32768
- acBackgroundColor = 128
- acBitProperties = 245760
- acContentColor = 64
- acContentLayout = 262144
- acContentProperties = 33662
- acDataFormat = 4
- acDataType = 2
- acDataTypeAndFormat = 6
- acEnableBackgroundColor = 16384
- acFlowDirBtoT = 131072
- acInvalidCellProperty = 0
- acLock = 1
- acMarginBottom = 8192
- acMarginLeft = 1024
- acMarginRight = 4096
- acMarginTop = 2048
- acMergeAll = 65536
- acRotation = 8
- acScale = 16
- acTextHeight = 512
- acTextStyle = 256
AcCellState
- class viktor.external.autocad.enums.AcCellState(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcCellStatevalues, mirroring the product API’s names so code reads like its docs.- acCellStateContentLocked = 1
- acCellStateContentModified = 32
- acCellStateContentReadOnly = 2
- acCellStateFormatLocked = 4
- acCellStateFormatModified = 64
- acCellStateFormatReadOnly = 8
- acCellStateLinked = 16
- acCellStateNone = 0
AcCellType
AcColor
AcColorMethod
- class viktor.external.autocad.enums.AcColorMethod(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcColorMethodvalues, mirroring the product API’s names so code reads like its docs.- acColorMethodByACI = 195
- acColorMethodByBlock = 193
- acColorMethodByLayer = 192
- acColorMethodByRGB = 194
- acColorMethodForeground = 197
AcCoordinateSystem
AcDataLinkUpdateDirection
AcDataLinkUpdateOption
- class viktor.external.autocad.enums.AcDataLinkUpdateOption(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcDataLinkUpdateOptionvalues, mirroring the product API’s names so code reads like its docs.- acUpdateOptionIncludeXrefs = 1048576
- acUpdateOptionNone = 0
- acUpdateOptionOverwriteContentModifiedAfterUpdate = 131072
- acUpdateOptionOverwriteFormatModifiedAfterUpdate = 262144
- acUpdateOptionUpdateFullSourceRange = 524288
AcDimArcLengthSymbol
AcDimArrowheadType
- class viktor.external.autocad.enums.AcDimArrowheadType(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcDimArrowheadTypevalues, mirroring the product API’s names so code reads like its docs.- acArrowArchTick = 4
- acArrowBoxBlank = 14
- acArrowBoxFilled = 15
- acArrowClosed = 2
- acArrowClosedBlank = 1
- acArrowDatumBlank = 16
- acArrowDatumFilled = 17
- acArrowDefault = 0
- acArrowDot = 3
- acArrowDotBlank = 12
- acArrowDotSmall = 11
- acArrowIntegral = 18
- acArrowNone = 19
- acArrowOblique = 5
- acArrowOpen = 6
- acArrowOpen30 = 10
- acArrowOpen90 = 9
- acArrowOrigin = 7
- acArrowOrigin2 = 8
- acArrowSmall = 13
- acArrowUserDefined = 20