viktor.external.autocad
AutoCADConnection
- class viktor.external.autocad.autocad.AutoCADConnection(session)
Bases:
_HandleConnectionNew 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.The SDK sends calls to the worker in chunks. A result is read when your code first uses its value: in
==,if,float(),int(),str(),print()or a loop. A failed call raisesviktor.errors.ExecutionErrorat that read, with the call and your line. Two things do not read a result: passing it to a later call, and unpacking it into names. So the example below sends all three calls in one chunk.result is Noneis alwaysFalseon an unread result; use== None. Passdefer=Falsetoconnect()/attach()to send each call on its own.circle = acad.ActiveDocument.ModelSpace.AddCircle([0, 0, 0], 1) low, high, _ = circle.GetBoundingBox() acad.ActiveDocument.ModelSpace.AddLine(low, high)See
batch()when one loop makes more than a few hundred calls.- batch()
- New in v14.37.0
Send all calls of the block to the worker as one job when the block ends. Without the block the SDK sends calls in chunks of a few hundred, each one round trip. The gain grows with the size of the block; below a few hundred calls it changes nothing. You cannot read a result inside the block: a read raises
RuntimeError. So doisinstance(),print(),str()andrepr()on a result. Read the results after the block. The block runs as one job under the sessiontimeout(300 s by default). For a very large block, increasetimeoutinconnect()/attach().with sap.batch(): for x, y in points: # 5000 points name, ret = sap.FrameObj.AddByCoord(x, y, 0, x, y, 3, "", "W12X26") sap.FrameObj.SetGroupAssign(name, "Columns") # 10000 calls went to the worker in one jobNeeds a deferred connection (
defer=True). Blocks cannot be nested. Calls made before the block are sent when the block starts.- Return type:
ContextManager[None,bool|None]
attach
- viktor.external.autocad.autocad.attach(timeout=300, defer=True)
- 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) – timeout in seconds for one chunk of calls; also bounds the attach itself, so keep it at or above the platform’s 30 second bind window.defer (
bool) – queue calls and send them to the worker in chunks; a result is fetched when your code first reads it (default: True). False sends every call at once and returns plain values.New in v14.37.0
- 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 chunk of calls took longer than
timeout
connect
- viktor.external.autocad.autocad.connect(timeout=300, defer=True)
- 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) – timeout in seconds for one chunk of calls. Opening the session waits for AutoCAD to be ready, so it must also cover starting AutoCAD up on the worker.defer (
bool) – queue calls and send them to the worker in chunks; a result is fetched when your code first reads it (default: True). False sends every call at once and returns plain values.New in v14.37.0
- 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 chunk of calls 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
AcDimCenterType
AcDimFit
AcDimFractionType
AcDimHorizontalJustification
- class viktor.external.autocad.enums.AcDimHorizontalJustification(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcDimHorizontalJustificationvalues, mirroring the product API’s names so code reads like its docs.- acFirstExtensionLine = 1
- acHorzCentered = 0
- acOverFirstExtension = 3
- acOverSecondExtension = 4
- acSecondExtensionLine = 2
AcDimLUnits
- class viktor.external.autocad.enums.AcDimLUnits(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcDimLUnitsvalues, mirroring the product API’s names so code reads like its docs.- acDimLArchitectural = 4
- acDimLDecimal = 2
- acDimLEngineering = 3
- acDimLFractional = 5
- acDimLScientific = 1
- acDimLWindowsDesktop = 6
AcDimPrecision
- class viktor.external.autocad.enums.AcDimPrecision(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcDimPrecisionvalues, mirroring the product API’s names so code reads like its docs.- acDimPrecisionEight = 8
- acDimPrecisionFive = 5
- acDimPrecisionFour = 4
- acDimPrecisionOne = 1
- acDimPrecisionSeven = 7
- acDimPrecisionSix = 6
- acDimPrecisionThree = 3
- acDimPrecisionTwo = 2
- acDimPrecisionZero = 0
AcDimTextMovement
AcDimToleranceJustify
AcDimToleranceMethod
AcDimUnits
- class viktor.external.autocad.enums.AcDimUnits(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcDimUnitsvalues, mirroring the product API’s names so code reads like its docs.- acDimArchitectural = 6
- acDimArchitecturalStacked = 4
- acDimDecimal = 2
- acDimEngineering = 3
- acDimFractional = 7
- acDimFractionalStacked = 5
- acDimScientific = 1
- acDimWindowsDesktop = 8
AcDimVerticalJustification
AcDragDisplayMode
AcDrawLeaderOrderType
AcDrawMLeaderOrderType
AcDrawingAreaSCMCommand
AcDrawingAreaSCMDefault
AcDrawingAreaSCMEdit
AcDrawingAreaShortCutMenu
AcDrawingDirection
AcDynamicBlockReferencePropertyUnitsType
AcEntityName
- class viktor.external.autocad.enums.AcEntityName(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcEntityNamevalues, mirroring the product API’s names so code reads like its docs.- ac3dFace = 1
- ac3dPolyline = 2
- ac3dSolid = 3
- acArc = 4
- acAttribute = 5
- acAttributeReference = 6
- acBlockReference = 7
- acCircle = 8
- acDgnUnderlay = 47
- acDim3PointAngular = 41
- acDimAligned = 9
- acDimAngular = 10
- acDimArcLength = 44
- acDimDiametric = 12
- acDimOrdinate = 13
- acDimRadial = 14
- acDimRadialLarge = 45
- acDimRotated = 15
- acDwfUnderlay = 46
- acEllipse = 16
- acExternalReference = 42
- acGroup = 37
- acHatch = 17
- acLeader = 18
- acLine = 19
- acMInsertBlock = 38
- acMLeader = 48
- acMLine = 40
- acMtext = 21
- acNurbSurface = 51
- acPViewport = 35
- acPdfUnderlay = 50
- acPoint = 22
- acPolyfaceMesh = 39
- acPolyline = 23
- acPolylineLight = 24
- acPolymesh = 25
- acRaster = 26
- acRay = 27
- acRegion = 28
- acShape = 29
- acSolid = 30
- acSpline = 31
- acSubDMesh = 49
- acTable = 43
- acText = 32
- acTolerance = 33
- acTrace = 34
- acXline = 36
AcExtendOption
AcFormatOption
AcGradientPatternType
AcGridLineStyle
AcGridLineType
- class viktor.external.autocad.enums.AcGridLineType(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcGridLineTypevalues, mirroring the product API’s names so code reads like its docs.- acHorzBottom = 4
- acHorzInside = 2
- acHorzTop = 1
- acInvalidGridLine = 0
- acVertInside = 16
- acVertLeft = 8
- acVertRight = 32
AcHatchObjectType
AcHatchStyle
AcHelixConstrainType
AcHelixTwistType
AcHorizontalAlignment
- class viktor.external.autocad.enums.AcHorizontalAlignment(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcHorizontalAlignmentvalues, mirroring the product API’s names so code reads like its docs.- acHorizontalAlignmentAligned = 3
- acHorizontalAlignmentCenter = 1
- acHorizontalAlignmentFit = 5
- acHorizontalAlignmentLeft = 0
- acHorizontalAlignmentMiddle = 4
- acHorizontalAlignmentRight = 2
AcISOPenWidth
- class viktor.external.autocad.enums.AcISOPenWidth(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcISOPenWidthvalues, mirroring the product API’s names so code reads like its docs.- acPenWidth013 = 13
- acPenWidth018 = 18
- acPenWidth025 = 25
- acPenWidth035 = 35
- acPenWidth050 = 50
- acPenWidth070 = 70
- acPenWidth100 = 100
- acPenWidth140 = 140
- acPenWidth200 = 200
- acPenWidthUnk = -1
AcInsertUnits
- class viktor.external.autocad.enums.AcInsertUnits(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcInsertUnitsvalues, mirroring the product API’s names so code reads like its docs.- acInsertUnitsAngstroms = 11
- acInsertUnitsAstronomicalUnits = 18
- acInsertUnitsCentimeters = 5
- acInsertUnitsDecameters = 15
- acInsertUnitsDecimeters = 14
- acInsertUnitsFeet = 2
- acInsertUnitsGigameters = 17
- acInsertUnitsHectometers = 16
- acInsertUnitsInches = 1
- acInsertUnitsKilometers = 7
- acInsertUnitsLightYears = 19
- acInsertUnitsMeters = 6
- acInsertUnitsMicroinches = 8
- acInsertUnitsMicrons = 13
- acInsertUnitsMiles = 3
- acInsertUnitsMillimeters = 4
- acInsertUnitsMils = 9
- acInsertUnitsNanometers = 12
- acInsertUnitsParsecs = 20
- acInsertUnitsUSSurveyFeet = 21
- acInsertUnitsUSSurveyInch = 22
- acInsertUnitsUSSurveyMile = 24
- acInsertUnitsUSSurveyYard = 23
- acInsertUnitsUnitless = 0
- acInsertUnitsYards = 10
AcInsertUnitsAction
AcKeyboardAccelerator
AcKeyboardPriority
AcLayerStateMask
- class viktor.external.autocad.enums.AcLayerStateMask(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcLayerStateMaskvalues, mirroring the product API’s names so code reads like its docs.- acLsAll = 65535
- acLsColor = 32
- acLsFrozen = 2
- acLsLineType = 64
- acLsLineWeight = 128
- acLsLocked = 4
- acLsNewViewport = 16
- acLsNone = 0
- acLsOn = 1
- acLsPlot = 8
- acLsPlotStyle = 256
AcLeaderType
AcLineSpacingStyle
AcLineWeight
- class viktor.external.autocad.enums.AcLineWeight(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcLineWeightvalues, mirroring the product API’s names so code reads like its docs.- acLnWt000 = 0
- acLnWt005 = 5
- acLnWt009 = 9
- acLnWt013 = 13
- acLnWt015 = 15
- acLnWt018 = 18
- acLnWt020 = 20
- acLnWt025 = 25
- acLnWt030 = 30
- acLnWt035 = 35
- acLnWt040 = 40
- acLnWt050 = 50
- acLnWt053 = 53
- acLnWt060 = 60
- acLnWt070 = 70
- acLnWt080 = 80
- acLnWt090 = 90
- acLnWt100 = 100
- acLnWt106 = 106
- acLnWt120 = 120
- acLnWt140 = 140
- acLnWt158 = 158
- acLnWt200 = 200
- acLnWt211 = 211
- acLnWtByBlock = -2
- acLnWtByLayer = -1
- acLnWtByLwDefault = -3
AcLoadPalette
AcLoftedSurfaceNormalType
- class viktor.external.autocad.enums.AcLoftedSurfaceNormalType(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcLoftedSurfaceNormalTypevalues, mirroring the product API’s names so code reads like its docs.- acAllNormal = 5
- acEndsNormal = 4
- acFirstNormal = 2
- acLastNormal = 3
- acRuled = 0
- acSmooth = 1
- acUseDraftAngles = 6
AcLoopType
- class viktor.external.autocad.enums.AcLoopType(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcLoopTypevalues, mirroring the product API’s names so code reads like its docs.- acHatchLoopTypeDefault = 0
- acHatchLoopTypeDerived = 4
- acHatchLoopTypeExternal = 1
- acHatchLoopTypePolyline = 2
- acHatchLoopTypeTextbox = 8
AcMLeaderContentType
AcMLeaderType
AcMLineJustification
AcMeasurementUnits
AcMenuFileType
AcMenuGroupType
AcMenuItemType
AcMergeCellStyleOption
- class viktor.external.autocad.enums.AcMergeCellStyleOption(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcMergeCellStyleOptionvalues, mirroring the product API’s names so code reads like its docs.- acMergeCellStyleConvertDuplicatesToOverrides = 4
- acMergeCellStyleCopyDuplicates = 1
- acMergeCellStyleIgnoreNewStyles = 8
- acMergeCellStyleNone = 0
- acMergeCellStyleOverwriteDuplicates = 2
AcMeshCreaseType
AcOlePlotQuality
AcOleQuality
AcOleType
AcOnOff
AcParseOption
AcPatternType
AcPlotOrientation
AcPlotPaperUnits
AcPlotPolicy
AcPlotPolicyForLegacyDwgs
AcPlotPolicyForNewDwgs
AcPlotRotation
AcPlotScale
- class viktor.external.autocad.enums.AcPlotScale(*values)
Bases:
IntEnumNew in 14.35.0AutoCAD
AcPlotScalevalues, mirroring the product API’s names so code reads like its docs.- ac100_1 = 32
- ac10_1 = 31
- ac1_1 = 16
- ac1_10 = 21
- ac1_100 = 27
- ac1_128in_1ft = 1
- ac1_16 = 22
- ac1_16in_1ft = 4
- ac1_2 = 17
- ac1_20 = 23
- ac1_2in_1ft = 10