Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. 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
  3. 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?
  4. 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)
  5. 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
  6. Today
  7. I don't tend to annotative dims as much as perhaps I should but will see what I can dig out
  8. 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
  9. 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).
  10. 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?
  11. 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
  12. 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
  13. 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.
  14. 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
  15. 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
  16. 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()))
  17. 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()))
  18. Danielm103

    Selection sets in Python.

    The real power is post filtering entity types, for example, we want the selection set to filter the visual selection set on screen, but then we want to separate out objects by type. SelectionSet.objectIds() method is overloaded to take an entity class description and returns the types that match. it does not open the object, so it’s extremely fast #returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select([(0, "TEXT,LWPOLYLINE,LINE")]) if ps != Ed.PromptStatus.eOk: raise RuntimeError("Selection Error! {}: ".format(ps)) # create a list of entites ant are opened for read texts = [Db.Text(id) for id in ss.objectIds(Db.Text.desc())] lines = [Db.Line(id) for id in ss.objectIds(Db.Line.desc())] plines = [Db.Polyline(id) for id in ss.objectIds(Db.Polyline.desc())] for text in texts: pass # do something for line in lines: pass # do something for pline in plines: pass # do something
  19. Danielm103

    Selection sets in Python.

    The SelectionSet class is an enumerable collection of ObjectIds, example #returns a PromptStatus and a SelectionSet class ps, ss = Ed.Editor.select() for id in ss: ent = Db.Entity(id) print(ent.isA().dxfName())
  20. Danielm103

    Selection sets in Python.

    SelectionSet filters can also be inline Ed.Editor.select([(0, "TEXT,LWPOLYLINE,LINE")])
  21. Filters Instead of creating a dedicated ResultBuffer class like in .NET, I decided to build a wrapper for Python’s built in types. Throughout the API, resbuf* or ResultBuffer are simply a list of tuples, in the format of a group code and a value typedValues = [(TYPE, VALUE)] Depending on the context the group code may be a Lisp type code, or in the case of selection sets, DXF codes. Here are two possible formats # long format filter = [ (Db.DxfCode.kDxfStart, "TEXT,LWPOLYLINE,LINE"), (Db.DxfCode.kDxfOperator, "<OR"), (Db.DxfCode.kDxfLayerName, "0"), (Db.DxfCode.kDxfLayerName, "8"), (Db.DxfCode.kDxfOperator, "OR>"), ] # short format filter = [ (0, "TEXT,LWPOLYLINE,LINE"), (-4, "<OR"), (8, "Layer1"), (8, "Layer2"), (8, "Layer3"), (-4, "OR>"), ]
  22. Entmake text style. (entmake '((0 . "STYLE") (100 . "AcDbSymbolTableRecord") (100 . "AcDbTextStyleTableRecord") (2 . "style name here") (70 . 0) (40 . 0.0) (41 . 1.0) (50 . 0.0) (71 . 0) (42 . 1.0) (3 . "Arial.ttf") (4 . "") ) ) use setvar for dimstyles nothing will be outputted to command prompt. (setvar 'DIMADEC 2) (setvar 'DIMALT "off") I think @Steven P has dug into this more.
  23. Yesterday
  24. BIGAL

    AUTOLISP FIELD AREA FOR PL BUG

    Also this as mentioned. (setq ent (entget (car (entsel "\nPick an object for layer name ")))) (setq MyLayerName (cdr (assoc 8 ent))) (setq allPolylines (ssget "_X" (list (0 . "*POLYLINE")(cons 8 MyLayerName))))
  25. I think you need to look at Entmake a style whether its a text style or a dimension style rather than trying to override current settings. trying to find a good simple example some else may have one.
  26. Steven P

    AUTOLISP FIELD AREA FOR PL BUG

    If it was me I would allow the user to select an entity on the layer rather than typing it in, or use something like BigAls multi getvals to select the layer from a list - saves typing errors. You can add to filters in the selection set: (setq allPolylines (ssget "_X" (list (0 . "*POLYLINE")(cons 8 MyLayerName)))) Note here that list is used if you want any of the filters to be programmatically. 'cons' used to construct the list and MyLayerName is a variable you might want to work out earlier in the LISP. Lee Mac has a very good explanation on his website for ssget. You can loop through your selection set and perhaps this snippet will help: ;;https://www.cadtutor.net/forum/topic/66091-centre-of-hatch/ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun c:CtrCoo (/ findctr a apt) ;;Center point of a hatch or a rectangle (defun findctr (en / pt) (command "_.Zoom" "_Object" en "") (setq pt (getvar 'viewctr)) (command "_.Zoom" "_Previous") pt ) (setq a (car (entsel "Select Rectangle: : ")) apt (findctr a) ) (command "_Text" "_Justify" "_MC" apt 0.1 0 apt) (princ) ) Copy FindCtr and use that to get the centre point of each object, using that as the insert point for the mtext. Maybe this will help you along?
  27. hi This is a very good lisp, can this be still upgraded to show the station of the selected lines also, at a certain distance south. like 20 or something.
  1. Load more activity
×
×
  • Create New...