Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. 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
  3. Today
  4. 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
  5. 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.
  6. 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
  7. 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
  8. 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()))
  9. 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()))
  10. 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
  11. 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())
  12. Danielm103

    Selection sets in Python.

    SelectionSet filters can also be inline Ed.Editor.select([(0, "TEXT,LWPOLYLINE,LINE")])
  13. 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>"), ]
  14. 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.
  15. Yesterday
  16. 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))))
  17. 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.
  18. 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?
  19. 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.
  20. GLAVCVS

    Hybrid parallel

    The result looks geometrically perfect I also started writing something on Friday with a similar approach. I'll post it when I finish it.
  21. GLAVCVS

    Hybrid parallel

    The result looks geometrically perfect I also started writing something on Friday with a similar approach. I'll post it when I finish it.
  22. GP_

    Hybrid parallel

    Updated code here
  23. A version also for closed polylines. Minimally tested... centerPline_v2.LSP
  24. Dear All, im trying create a annotative dimension style and text style style . annotation text style link to annotation dimstyle . create text style and dimethyl but annotative symbole not shown in dimension style and also text style )DIM-100 & DIM-200 is annotative dimension style) (defun c:TEST () (setvar "cmdecho" 0) (setvar "expert" 0) (command "undo" "be") (princ "\nFunction: Quickly create new dimension styles.\n") (if (not (tblsearch "STYLE" "STANDARD")) (command "style" "Standard" "txt" "" "1" "" "" "") ) (if (not (tblsearch "STYLE" "STANDARD")) (command ".-style" "STANDARD" "TXT" "0" "1" "0" "N" "N" "N") ) (command "dimadec" "2" "dimalt" "off" "dimalttz" "1" "dimaltu" "2" "dimassoc" "2" "dimasz" "1" "dimatfit" "3" "dimaunit" "0" "dimazin" "0" "dimblk" "_ARCHTICK" "dimcen" "0" "dimclrd" "0" "dimclre" "0" "dimclrt" "0" "dimdec" "2" "dimdle" "0.00" "dimdli" "0.05" "dimdsep" "." "dimexe" "0.35" "dimexo" "0.35" "dimfxlon" "off" "dimgap" "0.5" "dimjust" "0" "dimldrblk" "_ARCHTICK" "dimlfac" "1" "dimlunit" "2" "dimscale" "1" "dimtad" "1" "dimtdec" "2" "dimtfac" "1" "dimtfill" "0" "dimtfillclr" "0" "dimtih" "off" "dimtix" "off" "dimtmove" "0" "dimtofl" "on" "dimtol" "off" "dimtolj" "1" "dimtxsty" "Standard" "dimtxt" "2.5" "dimtzin" "1" "dimupt" "off" "dimzin" "1" ) (if (not (tblsearch "dimstyle" "TEST-123")) (command "dimstyle" "S" "TEST-123") ) ;; -------------------------------------- (if (not (tblsearch "STYLE" "TEST-100")) (command ".-style" "TEST-100" "Calibri" "0" "1" "0" "N" "N" "N") ) (setvar "DIMTOL" 1) (setvar "DIMTM" 0.05) (setvar "DIMTP" 0.05) (setvar "DIMTXSTY" "TEST-100") ;; Create or update dimension style (if (not (tblsearch "dimstyle" "DIM-100")) (progn (command ".-dimstyle" "S" "DIM-100") ) (command ".-dimstyle" "R" "DIM-100") ) ;; -------------------------------------- (if (not (tblsearch "STYLE" "TEST-200")) (command ".-style" "TEST-200" "ARIAL" "0" "1" "0" "N" "N" "N") ) (setvar "DIMTOL" 1) (setvar "DIMTM" 0.10) (setvar "DIMTP" 0.10) (setvar "DIMTXSTY" "TEST-200") (if (not (tblsearch "dimstyle" "DIM-200")) (progn (command ".-dimstyle" "S" "DIM-200") ) (command ".-dimstyle" "R" "DIM-200") ) (command "undo" "e") (alert "\nPrompt:\nDimension style creation completed!\n") (princ) ) OPT-2 THIS OPTION TEXT STYLE NOT CRETED IN ANNOTATIVE STYLE AND ONE MORE QUERT I WANT TEST-123 IS NORMAL DIM STYLE (defun c:TEST (/ oldcmdecho oldexpert) (setq oldcmdecho (getvar "cmdecho") oldexpert (getvar "expert")) (setvar "cmdecho" 0) (setvar "expert" 5) (command "_.undo" "_begin") (if (not (tblsearch "STYLE" "Standard")) (command "_.-style" "Standard" "txt" "2.5" "" "" "" "") ) (if (not (tblsearch "STYLE" "TEST-100")) (command "_.-style" "TEST-100" "Calibri" "2.5" "" "" "" "") ) (if (not (tblsearch "STYLE" "TEST-200")) (command "_.-style" "TEST-200" "Arial" "2.5" "" "" "" "") ) (while (> (getvar "cmdactive") 0) (command "")) (if (not (tblsearch "DIMSTYLE" "TEST-123")) (progn (setvar "DIMTOL" 0) (setvar "DIMTXSTY" "Standard") (command "_.-dimstyle" "_S" "TEST-123") (while (> (getvar "cmdactive") 0) (command "")) ) ) (if (not (tblsearch "DIMSTYLE" "DIM-100")) (progn (setvar "DIMTOL" 1) (setvar "DIMTM" 0.05) (setvar "DIMTP" 0.05) (setvar "DIMTXSTY" "TEST-100") (setvar "DIMTDEC" 2) (command "_.-dimstyle" "_S" "DIM-100") (while (> (getvar "cmdactive") 0) (command "")) ) ) ;; DIM-200 - With tolerances (if (not (tblsearch "DIMSTYLE" "DIM-200")) (progn (setvar "DIMTOL" 1) (setvar "DIMTM" 0.10) (setvar "DIMTP" 0.10) (setvar "DIMTXSTY" "TEST-200") (setvar "DIMTDEC" 2) (command "_.-dimstyle" "_S" "DIM-200") (while (> (getvar "cmdactive") 0) (command "")) ) ) (command "_.undo" "_end") (setvar "cmdecho" oldcmdecho) (setvar "expert" oldexpert) (princ "\nTEST command completed successfully!") (princ) )
  25. Danielm103

    Hybrid parallel

    This is kind of close, I split each line into some number of segments, then use closest point. Simplify reduces the number of segments, but changes the precision. Not sure if you can do this in lisp import traceback from pyrx import Db, Ed, Ge, Ap, Rx, Gs @Ap.Command() def centline(): try: ps1, id1, _ = Ed.Editor.entSel("\nPick 1") ps2, id2, _ = Ed.Editor.entSel("\nPick 2") pl1 = Db.Polyline(id1) pl2 = Db.Polyline(id2) crv1 = pl1.getAcGeCurve() crv2 = pl2.getAcGeCurve() # 200 can be a function of lenth, both must be the same smp1, _ = crv1.getSamplePoints(100) smp2, _ = crv2.getSamplePoints(100) spl1 = pl1.getSplitCurves(smp1) spl2 = pl2.getSplitCurves(smp2) pnts = [] for l, r in zip(spl1, spl2): cl = l.getAcGeCurve() cr = r.getAcGeCurve() poc1, poc2 = cl.getClosestPointsTo(cr) p1 = poc1.point3d() p2 = poc2.point3d() pnts.append(p1 + (p2 - p1) * 0.5) db = Db.curDb() cs = db.currentSpace(Db.OpenMode.kForWrite) npl = Db.Polyline(pnts) npl.simplify(0.01) npl.setLayer("0") npl.setColor(1) cs.appendAcDbEntity(npl) except Exception as err: traceback.print_exception(err) drawing AxisExample_dan.dwg
  26. @Tamim Try this code and see if it helpful: (prompt "\nTo run a LISP type: LPL") (princ) (defun c:LPL ( / ss len circ txt_height lst i minPt maxPt midPt circle inc ang num ptlist k pt ssn pl_len ins_pt) (prompt "\nSelect all TEXT entities:\n") (setq ss (ssget (list (cons 0 "TEXT"))) len (sslength ss) circ 0.05 ;; radius of the circle can be changeable txt_height 0.01 ;; mtext height can be changeable lst (list) i 0 ) (while (< i len) (vla-GetBoundingBox (vlax-ename->vla-object (ssname ss i)) 'minPt 'maxPt) (setq minPt (vlax-safearray->list minPt) maxPt (vlax-safearray->list maxPt) midPt (mapcar '* (mapcar '+ minPt maxPt) (list 0.5 0.5)) ) (entmake (list (cons 0 "CIRCLE") (cons 100 "AcDbEntity") (cons 100 "AcDbCircle") (cons 8 (getvar 'clayer)) (cons 10 midpt) (cons 40 circ))) (setq circle (entlast) inc 0.25 ang 0 num (fix (/ (* pi 2) inc)) ptlist (list) k 0 ) (repeat num (setq pt (polar midPt ang circ) ptlist (append (list pt) ptlist) ang (+ ang inc) ) ) (setq ssn (ssget "_F" ptlist (list (cons 0 "LWPOLYLINE"))) pl_len (getpropertyvalue (ssname ssn k) "Length") ) (entdel circle) (setq lst (cons (list (cdr (assoc 1 (entget (ssname ss i)))) "\t " (rtos pl_len 2 3) "\\P") lst) i (1+ i) ) ) (setq lst (vl-sort lst (function (lambda (x e) (< (atoi (substr (car x) 3 (strlen (car x)))) (atoi (substr (car e) 3 (strlen (car e)))))))) lst (cons (list "\\fArial|b0|i0|c0|p34;S.No\tLength Ft\\P") lst) ins_pt (getpoint "\nPick the insertation point:") ) (entmake (list (cons 0 "MTEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbMText") (cons 8 (getvar 'clayer)) (cons 10 ins_pt) (cons 40 txt_height) (cons 72 1) (cons 1 (apply 'strcat (mapcar '(lambda (x) (apply 'strcat x)) lst))))) (prompt "\nThe labels and the length of the polylines were added as MTEXT!") (princ) ) Also, you can see the short video example of how it works. LengthPolylineMtext.mp4 Best regards.
  27. PGia

    Hybrid parallel

    Thanks @Danielm103 That seems pretty accurate, although geometrically massive. It seems like there are a lot of points that aren't necessary. I guess something elegant should be only what's geometrically necessary. But I wonder what the result looks like when the geometry of the reference polylines is more extensive and varied.
  28. Danielm103

    Hybrid parallel

    Shapley or geopandas can create this, there’s artifacts though. The algorithm is some sort of Voronoi https://centerline.readthedocs.io/en/latest/# https://gis.stackexchange.com/questions/474810/how-to-get-the-centerline-of-a-polygon-without-artefacts-in-python a bit wonky
  1. Load more activity
×
×
  • Create New...