Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. Trying to add the purple line values will introduce a new problem of overlapping text. trying to remember with CIV3D add extra pts in a long section in particular, one way is add that chainage as part of the alignment. Using say Civil Site Design it has this add extra chainages feature built in. Runs in Civ3D. You can do a mini range start-end chainge, spacing and so on.
  3. Today
  4. Better late the never this will add a " to the end of dimensions for a drawing that is set to IPS. tho doesn't work quite right when tolerances are used. will also prompt you if you are going to overwrite any data Sub addtick() Dim swApp As SldWorks.SldWorks, swModel As SldWorks.ModelDoc2, swDraw As SldWorks.DrawingDoc Dim swView As SldWorks.View, swDispDim As SldWorks.DisplayDimension, swDim As SldWorks.Dimension Dim unitSystem As Long, okRun As Boolean, sCurrSuffix As String, id As String Set swApp = Application.SldWorks Set swModel = swApp.ActiveDoc If swModel Is Nothing Then MsgBox "No active document.", vbExclamation, "Add Inch Tick" Exit Sub End If If swModel.GetType <> swDocDRAWING Then MsgBox "This macro only runs on drawings.", vbExclamation, "Add Inch Tick" Exit Sub End If unitSystem = swModel.Extension.GetUserPreferenceInteger( _ swUserPreferenceIntegerValue_e.swUnitSystem, _ swUserPreferenceOption_e.swDetailingNoOptionSpecified) If unitSystem <> swUnitSystem_e.swUnitSystem_IPS Then MsgBox "This macro will only run in IPS(Inch, Pound, Second) Drawing.", vbExclamation, "Add Inch Tick" Exit Sub End If Set swDraw = swModel Set swView = swDraw.GetFirstView Do While Not swView Is Nothing Set swDispDim = swView.GetFirstDisplayDimension5 Do While Not swDispDim Is Nothing Set swDim = swDispDim.GetDimension sCurrSuffix = swDispDim.GetText(swDimensionTextSuffix) If sCurrSuffix <> "" And Not sCurrSuffix = """" Then If MsgBox("Overwrite """ & sCurrSuffix & """?", vbQuestion + vbYesNo) = vbYes Then swDispDim.SetText swDimensionTextSuffix, """" End If Else swDispDim.SetText swDimensionTextSuffix, """" End If Set swDispDim = swDispDim.GetNext3 Loop Set swView = swView.GetNextView Loop swModel.GraphicsRedraw2 MsgBox "Ticks Added to Drawing" End Sub
  5. Here, I have the profile generated from Civil 3D. The elevations and stations are generated at every 25m interval (white lines), but the crossings are not included. So if I get a lisp that will generate the staion and elevations for the crossings (pink lines) same as the details for the white lines. with your Yval we can get the elevations but need the stations also.
  6. Ooops .. code updated at that post. Here's the problem ( missing parenthesis and color number)
  7. Well, for the DEBUG CONSOLE, I stumbled on the problem when I wasn't searching. I had a filter active. On deleting it, suddenly I saw all the blue reports. Yay!
  8. Worked Great! Thanks for the tip.
  9. Danielm103

    Anatomy of an AcDbObject in Python.

    Best practice for checking types is to use the ObjectId as the AcRxClass is cached when the drawing is opened in CAD. it’s much faster than opening the object db = Db.curDb() for id in db.modelSpace(): if id.isDerivedFrom(Db.Line.desc()): # check the id line = Db.Line(id)
  10. Danielm103

    Anatomy of an AcDbObject in Python.

    Note with casting, the cast internally increases the reference count to the same C++ pointer. If you close one, the other will be closed. Like entangled particles, if Alice changes something, Bob will observe the change line = Db.Line() curve = Db.Curve.cast(line) print(line,curve) #<PyDb.Line object at 0x000001FB834B5940> <PyDb.Curve object at 0x000001FB83577240>
  11. Danielm103

    Anatomy of an AcDbObject in Python.

    Checking Db.Object types and casting Every database object has a static description Db.Line.desc() https://help.autodesk.com/view/OARX/2025/ENU/?guid=OARX-RefGuide-AcRxObject__desc Every database object has an instance method to verify the type https://help.autodesk.com/view/OARX/2025/ENU/?guid=OARX-RefGuide-AcRxObject__isA examples: @Ap.Command() def doit(): try: # check types line = Db.Line() print(line.isA() == Db.Line.desc()) print(line.isA().isDerivedFrom(Db.Line.desc())) print(line.isKindOf(Db.Line.desc())) #check types print(line.isA().isDerivedFrom(Db.Curve.desc())) print(line.isKindOf(Db.Curve.desc())) ps, id, pnt = Ed.Editor.entSel("\nSelect Entity: ") curve = Db.Curve(id) if curve.isKindOf(Db.Line.desc()): #PyRx does not check in the cast cline = Db.Line.cast(curve) print(line.isA() == Db.Line.desc()) print(line.isA().isDerivedFrom(Db.Line.desc())) print(line.isKindOf(Db.Line.desc())) print(line.isA().isDerivedFrom(Db.Curve.desc())) print(line.isKindOf(Db.Curve.desc())) except Exception as err: traceback.print_exception(err) Command: DOIT True True True True True Select Entity: True True True True True
  12. Danielm103

    Anatomy of an AcDbObject in Python.

    The Cons: You have to consider the states of the objects when writing your code, for example function dobad throws an exception Db.ErrorStatusException: Exception!(eWasOpenForRead) because space and model are the same object, to be opened in different states @Ap.Command() def dobad(): try: db = Db.curDb() space = Db.BlockTableRecord(db.modelSpaceId()) for id in space.objectIds(Db.Line.desc()): line = Db.Line(id) # ...... model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite) model.appendAcDbEntity( Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(100, 100, 0))) #Db.ErrorStatusException: Exception!(eWasOpenForRead) except Exception as err: traceback.print_exception(err) @Ap.Command() def dogood(): try: db = Db.curDb() space = Db.BlockTableRecord(db.modelSpaceId()) for id in space.objectIds(Db.Line.desc()): line = Db.Line(id) # ...... space.upgradeOpen() # change to write space.appendAcDbEntity( Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(100, 100, 0))) except Exception as err: traceback.print_exception(err) @Ap.Command() def dobest(): try: db = Db.curDb() readlines(db) #... writelines(db) except Exception as err: traceback.print_exception(err) def readlines(db): space = Db.BlockTableRecord(db.modelSpaceId()) for id in space.objectIds(Db.Line.desc()): line = Db.Line(id) def writelines(db): model = Db.BlockTableRecord(db.modelSpaceId(), Db.OpenMode.kForWrite) model.appendAcDbEntity( Db.Line(Ge.Point3d(0, 0, 0), Ge.Point3d(100, 100, 0))) best practice is to separate out operations if you run into conflicts
  13. PGia

    Hybrid parallel

    Hi The perpendicular distances to the axis seem to be always the same on both sides of the axis, using only the necessary number of vertices. I think this is what I was looking for. Thank you very much Just one more thing: does the functionality of this code depend on the availability of Express Tools?
  14. Danielm103

    Anatomy of an AcDbObject in Python.

    The Pros: You can leave the entities open for longer, set multiple properties without the overhead of multiple open/close. Consider adding a large number of entities to modelspace, with PyRx, you can leave modelspace opened for write for the entire operation @Ap.Command() def doit(): try: db = Db.curDb() space = Db.BlockTableRecord(db.currentSpaceId(), Db.OpenMode.kForWrite) for idx in range(20): nidx = idx + 100 space.appendAcDbEntity( Db.Line(Ge.Point3d(idx, idx, idx), Ge.Point3d(nidx, nidx, nidx))) except Exception as err: traceback.print_exception(err)
  15. When you call a method against an entity in Lisp or ActiveX, AutoCAD manages the state of the entity for you. The sequence is: - Lock the document - Open the Object kForRead/kForWrite - Perform the operation - Close the Object - Unlock the document The overhead starts to build up if you’re setting lots of dbobject Properties Unlike Lisp or ActiveX, Db.DbObject, in Python, .NET, and ObjectARX you have to manage the object’s lifetime. .NET mainly uses the transaction manager for this, I won’t be getting into that Writing in Python(PyRx) is almost identical to modern C++ in that both systems use smart pointers to help manage the state for you. Consider C++ static void AcRxPyApp_idoit(void) { auto [ps, id, pnt] = entsel(L"\nSelect Entity: "); AcDbEntityPointer pEnt(id, AcDb::OpenMode::kForWrite); pEnt->setLayer(L"0"); } vs Python def doit(): try: ps, id, pnt = Ed.Editor.entSel("\nSelect Entity: ") ent = Db.Entity(id,Db.OpenMode.kForWrite) ent.setLayer("0") except Exception as err: traceback.print_exception(err) In Both C++ and Python, ent (pEnt) is closed at the end of the function scope
  16. I don't tend to annotative dims as much as perhaps I should but will see what I can dig out
  17. I regularly use the attached dynamic block but have a big issue in that I cannot control the attribute text size without having to explode and then individually edit every bock. The attribute is defined with a unique text style and was hoping to use that to control but this does not work, nor does trying to use annotative elements. I tried making the text style annotative, the block it is part of and the dynamic block that contains the sub blocks - no luck. Is there a solution to this? Beam.dwg
  18. SLW210

    Hybrid parallel

    OP's AxisExample.dwg shows DWG file was saved by an application that was not developed or licensed by Autodesk. Both Gian's @GP_ and Daniel's @Danielm103 are still slightly off from @PGia manual examples. With @GP_ CPL I get... Command: CPL Cannot invoke (command) from *error* without prior call to (*push-error-using-command*). Converting (command) calls to (command-s) is recommended. But it runs.. here is OP's (blue) and Gian's (white).
  19. I tried installing this, but I get the following text in the command prompt - "error: extra cdrs in dotted pair on input". Does anyone know how to fix the error?
  20. Hi, CADTutor people! I'd love to share my exciting success. And I need a little help if anybody can give it. I've been programming in AutoLISP for 30 years (remember XTree Gold, the Kelvinator, and that colorful DOS lisp editor?), and I decided to give VS Code yet another try on Oct 4. It was generally successful enough that I decided to commit to it. Then one week ago I happened upon a tutorial for the Copilot AI agent, fired it up with Claude Sonnet (based on hive mind advice), and have been in heaven (and not sleeping) all week; I have a lot of pent-up wish list for open source project CNM from myself and users, and I am getting old and (sometimes) tired. Claude Sonnet under Copilot is amazing! But about VS Code: On the whole I am still not looking back, especially with the AI helps and agent. I even like the debugger a lot. And I plan to have ai help me write a little FAS compiler loop. But I don't like the AutoLISP Extension's formatter. And for the life of me I cannot read the minds of the programmers when it comes to loading code. To make matters worse, in the last few days I can figure out how to load code or get the Console to respond. Here's a bug report in case there are great masters about this here: I used to see blue text in the output (or console?) area at the bottom stating what files were loaded. And I could put expressions in the Console. But now I can't get either one to work. I see that there is a green Restart circle at the top and a blue "Load lisp" button on the bottom status bar. The blue status bar and green restart circle indicate that a debug session is running, or in other words that AutoCAD is connected. But it was dismaying to me to learn that the green restart button can load only the file that was active when debugging started. You can't switch to another file and load it without disconnecting and starting a new debug session. You can use the blue "Load lisp" to load other files. But more than half the time that would fail with an incomprehensible message that it could not be loaded because it has changed. "Well, yeah! That's why I want to load it." I see that Autodesk says "Tip: If you need to debug multiple LSP files, it is recommended to load those files with the AutoLISP LOAD function in the LSP file that is in the active editor window before starting a new debug session." So maybe they never could get this to work the way they wanted to. The good news is that if you load from AutoCAD, you still can debug. So all this is not a deal killer. I reinstalled the extension. Maybe I need to reinstall VS Code (again). Any ideas, or just want to talk about my amazing experience with Copilot/Claude? Tom
  21. hi, this Lips working pefrect but this one i used other cad file cant work result shows" Select all TEXT entities: Select objects: Specify opposite corner: 12 found Select objects: ; error: bad argument type: lselsetp nil" advice pls Line Length Sample v2.dwg
  22. Hi @symoin If you can provide the an example file with explanations inside of what you want, I can try it to modified the code for your purposes. Best regards.
  23. maahee

    Dimensions

    @devitg sample dwg upload for reference @GLAVCVS It may not function correctly, possibly due to the direction(clockwise or counterclockwise) of the arc or because it does not meet the point on the arc. mb.dwg
  24. Danielm103

    Selection sets in Python.

    SelectionSet class methods class SelectionSet: def add(self, id: Db.ObjectId, /) -> None: ... def adsname(self, /) -> Db.AdsName: ... def clear(self, /) -> None: ... def hasMember(self, id: Db.ObjectId, /) -> bool: ... def objectIdArray(self, desc: Rx.RxClass = Db.Entity, /) -> Db.ObjectIdArray: ... def objectIds(self, desc: Rx.RxClass = Db.Entity, /) -> list[Db.ObjectId]: ... def remove(self, id: Db.ObjectId, /) -> None: ... def size(self, /) -> int: ... def ssNameX(self, val: int = 0, /) -> list: ... def ssSetFirst(self, /) -> bool: ... def ssXform(self, xform: Ge.Matrix3d, /) -> Ed.PromptStatus: ... def toList(self, /) -> list[Db.ObjectId]: ... Note, ObjectIdArray is basically the same as list[Db.ObjectId], but the memory is allocated in C++ instead of Python. There may be performance reasons to choose one of the the other, but for now, they can be used interchangeably
  25. Danielm103

    Selection sets in Python.

    Lets say we want only lines and arcs, but still want to use AcDbCurve class, pass a list of descriptions # returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select([(8, "0")]) if ps != Ed.PromptStatus.eOk: raise RuntimeError("Selection Error! {}: ".format(ps)) curves = [Db.Curve(id) for id in ss.objectIds([Db.Line.desc(),Db.Arc.desc()])] for curve in curves: print(curve.getDistAtParam(curve.getEndParam()))
  26. Danielm103

    Selection sets in Python.

    Support derived types, Lets say you want to get all the objects in the set that are derived from AcDbCurve, to do some sort of base class operation (AcDb2dPolyline, AcDb3dPolyline, AcDbArc, AcDbCircle, AcDbEllipse, AcDbLeader, AcDbLine, AcDbPolyline, AcDbRay, AcDbSpline, AcDbXline) # returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select([(8, "0")]) if ps != Ed.PromptStatus.eOk: raise RuntimeError("Selection Error! {}: ".format(ps)) curves = [Db.Curve(id) for id in ss.objectIds(Db.Curve.desc())] for curve in curves: print(curve.getDistAtParam(curve.getEndParam()))
  1. Load more activity
×
×
  • Create New...