All Activity
- Past hour
-
Daniel, For total LISP hacks like me who barely get by piecing together LISP code that we find online. I don't even know where to begin with trying to utilize the awesome python code that you share. It isn't as easy as opening Notepad and copying and pasting code and then saving as a different filetype. Then dragging that file into your drawing area to load and use. So I am asking as a total beginner, Where do I start? Is there a simple breakdown with instructions for us curious newbies? Thanks ~Greg BTW - Thanks for all the stuff that you share
- Today
-
What we have already just cleans up an incoming CAD file like unlocking all layers, color to ByLayer, Audit, PU, -PU(regapps), and changing the units. We use AutoCAD LT and I don't think we need to change nested hatches because the hatches I want to code are usually on the surface and include pavement, sidewalk, etc., and not in another block. I would want to include dynamic blocks to be able to be exploded as well since alot of utility symbols are dynamic blocks. I've never heard of anonymous blocks... (defun C:CLEANUP ( / allobjects hatchss i hobj hcount) (command "-layer" "unlock" "*" "") ; Unlocks all layers to make them editable (setq allobjects (ssget "_X" )) (command "_.CHPROP" allobjects "" "_color" "ByLAyer" "") ; Sets the color of all objects to ByLayer (command "_AUDIT" "Yes") (command "_PURGE" "Regapps" "*" "No") (command "_PURGE" "All" "*" "No") (setvar "lunits" 2) ; Set linear units to decimal (setvar "aunits" 0) ; Set angular units to decimal (command "_INSUNITS" "0") ; Specifies the drawing units as unitless ;; Turn off Annotative property on all hatch objects (vl-load-com) (setq hcount 0) (if (setq hatchss (ssget "_X" '((0 . "HATCH")))) (progn (setq i 0) (while (< i (sslength hatchss)) (setq hobj (vlax-ename->vla-object (ssname hatchss i))) (if (vlax-property-available-p hobj "Annotative") (progn (vla-put-Annotative hobj :vlax-false) (setq hcount (1+ hcount)) ) ) (setq i (1+ i)) ) ) ) (princ (strcat "\n" (itoa hcount) " hatch(es) set to non-annotative.")) (princ "\n\nFile has been cleaned.") ) (princ)
-
There are some items in the database, where the only option is to use entGet, I.e. ACAD_FIELDLIST is not exposed to ARX See: https://www.cadtutor.net/forum/topic/99220-python-change-precision-of-all-fields-in-a-drawing/
-
And top it off with entMake from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit5() -> None: Db.Core.entMake([(0 , "LINE"),(10, Ge.Point3d(0, 0, 0)),(11, Ge.Point3d(100, 100, 0))])
-
This might be better example, maybe similar to the COND expression? from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit4() -> None: ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) #get the result buffer rb = Db.Core.entGet(id) # Process the result buffer using structural pattern matching updated_rb = [] for item in rb: match item: case (10, _): updated_rb.append((10, Ge.Point3d(0, 0, 0))) case (11, _): updated_rb.append((11, Ge.Point3d(100, 100, 0))) case _: updated_rb.append(item) # Apply changes back to the AutoCAD database Db.Core.entMod(updated_rb)
-
In Python, tuples are immutable, so if we want to modify the list, you have to replace it. In this sample we modify the start and end of a line from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit3() -> None: #entsel with a filter ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) #get the result buffer rb = Db.Core.entGet(id) # Loop through the result buffer list and modify matching DXF codes for i, item in enumerate(rb): dxf_code = item[0] if dxf_code == 10: rb[i] = (10, Ge.Point3d(0, 0, 0)) elif dxf_code == 11: rb[i] = (11, Ge.Point3d(100, 100, 0)) # Apply changes back to the AutoCAD database Db.Core.entMod(rb)
-
In Python, there isn’t an assoc function, we can iterate through and search for a DXF code from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit1() -> None: # entsel with a filter ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) # get the result buffer rb = Db.Core.entGet(id) # 1. Analog to Lisp: (assoc 8 rb) -> Returns the full pair (8, "LayerName") dxf_code, value = next((item for item in rb if item[0] == 8), None) # 2. Extract just the value safely if dxf_code: print(f"The layer is: {value}")
-
Danielm103 started following Python for AutoLISP Users part 1:
-
I thought I might write some samples to help guide lisp users that are interested in trying out Python. Long time lisp users will feel right at home using result buffers (DXF Lists). In PyRx, it’s wrappers around the old school C ADS functions, I.e. ads_entget, yay, like driving an F-150 with a toilet bowl plunger as the gear shift. In Python, most of these old functions reside in Db.Core The resbuf* linked lists are wrapped into a list of tuples.. does this output look familiar? from pyrx import Ap, Db, Ed, Ge @Ap.Command() def doit0() -> None: #entsel with a filter ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Line.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) #get the result buffer rb = Db.Core.entGet(id) print(rb) # [ # (-1, PyDb.ObjectId(1de8bf954d0)), # (0, 'LINE'), # (330, PyDb.ObjectId(1de8bf9a1f0)), # (5, '265'), # (100, 'AcDbEntity'), # (67, 0), # (410, 'Model'), # (8, '0'), # (100, 'AcDbLine'), # (10, PyGe.Point3d(0.00000000000000,0.00000000000000,0.00000000000000)), # (11, PyGe.Point3d(100.00000000000000,100.00000000000000,0.00000000000000)), # (210, PyGe.Point3d(0.00000000000000,0.00000000000000,1.00000000000000)) # ]
-
EnM4st3r started following Changing the precision of fields
-
those are attribute references of a block. Since vla-fieldcode only works on Text and mtext i used Lee Macs fieldcode instead https://www.lee-mac.com/fieldcode.html It should work on Blocks Attributereferences as well now. (defun c:change_prec (/ *error* acdoc undo-mark ss target index ename obj att field-string revised-string) (defun *error* (msg) (if undo-mark (progn (vl-catch-all-apply 'vla-EndUndoMark (list acdoc)) (setq undo-mark nil) ) ) (if (and msg (not (wcmatch (strcase msg) "*BREAK*,*CANCEL*,*EXIT*")) ) (princ (strcat "\nError: " msg)) ) (princ) ) (setq acdoc (vla-get-ActiveDocument (vlax-get-acad-object))) (prompt "\nSelect text, MText, or attributed blocks: ") (while (null (setq ss (ssget '((0 . "TEXT,MTEXT,INSERT"))))) (prompt "\nNo valid text, MText, or blocks selected.") ) (initget 1 "0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Current") (setq target (getkword "\nTarget precision [0/1/2/3/4/5/6/7/8/9/10/11/12/13/14/15/16/Current]: ")) (vla-StartUndoMark acdoc) (setq undo-mark T) (repeat (setq index (sslength ss)) (setq index (1- index) ename (ssname ss index) obj (vlax-ename->vla-object ename) ) (cond ;; Text or MText ((wcmatch (vla-get-ObjectName obj) "AcDbText,AcDbMText") (setq field-string (vla-FieldCode obj)) (if (and field-string (setq revised-string (replacePrecision field-string target)) ) (vla-put-TextString obj revised-string) ) ) ;; Block reference with editable attributes ((vlax-method-applicable-p obj 'GetAttributes) (foreach att (vlax-invoke obj 'GetAttributes) (setq field-string (LM:fieldcode (vlax-vla-object->ename att))) (if (and field-string (setq revised-string (replacePrecision field-string target)) ) (vla-put-TextString att revised-string) ) ) ) ) ) (vla-EndUndoMark acdoc) (setq undo-mark nil) (vla-Regen acdoc acActiveViewport) (princ) ) (defun replacePrecision (fieldStr target / nbs prec_source return) (setq nbs 0) (cond ((vl-string-search "%<\\" fieldStr nbs) (while nbs (if (setq nbs (vl-string-search "%pr" fieldStr (setq tmp_nbs nbs))) (setq prec_source (itoa (atoi (substr fieldStr (+ nbs 4) 2))) fieldStr (vl-string-subst (if (eq target "Current") (strcat "%pr" (itoa (getvar "LUPREC"))) (strcat "%pr" target) ) (strcat "%pr" prec_source) fieldStr tmp_nbs ) nbs (1+ nbs) ) ) ) (setq return fieldStr) ) ) return ) ;; Field Code - Lee Mac ;; Returns the field expression associated with an entity (defun LM:fieldcode ( ent / replacefield replaceobject fieldstring enx ) (defun replacefield ( str enx / ent fld pos ) (if (setq pos (vl-string-search "\\_FldIdx" (setq str (replaceobject str enx)))) (progn (setq ent (assoc 360 enx) fld (entget (cdr ent)) ) (strcat (substr str 1 pos) (replacefield (fieldstring fld) fld) (replacefield (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx))) ) ) str ) ) (defun replaceobject ( str enx / ent pos ) (if (setq pos (vl-string-search "ObjIdx" str)) (strcat (substr str 1 (+ pos 5)) " " (LM:ObjectID (vlax-ename->vla-object (cdr (setq ent (assoc 331 enx))))) (replaceobject (substr str (1+ (vl-string-search ">%" str pos))) (cdr (member ent enx))) ) str ) ) (defun fieldstring ( enx / itm ) (if (setq itm (assoc 3 enx)) (strcat (cdr itm) (fieldstring (cdr (member itm enx)))) (cond ((cdr (assoc 2 enx))) ("")) ) ) (if (and (wcmatch (cdr (assoc 0 (setq enx (entget ent)))) "TEXT,MTEXT,ATTRIB,MULTILEADER,*DIMENSION") (setq enx (cdr (assoc 360 enx))) (setq enx (dictsearch enx "ACAD_FIELD")) (setq enx (dictsearch (cdr (assoc -1 enx)) "TEXT")) ) (replacefield (fieldstring enx) enx) ) ) ;; ObjectID - Lee Mac ;; Returns a string containing the ObjectID of a supplied VLA-Object ;; Compatible with 32-bit & 64-bit systems (defun LM:ObjectID ( obj ) (eval (list 'defun 'LM:ObjectID '( obj ) (if (and (vl-string-search "64" (getenv "PROCESSOR_ARCHITECTURE")) (vlax-method-applicable-p (vla-get-utility (LM:acdoc)) 'getobjectidstring) ) (list 'vla-getobjectidstring (vla-get-utility (LM:acdoc)) 'obj ':vlax-false) '(itoa (vla-get-objectid obj)) ) ) ) (LM:ObjectID obj) ) ;; Active Document - Lee Mac ;; Returns the VLA Active Document Object (defun LM:acdoc nil (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object)))) (LM:acdoc) )
-
I have not played in python and I will give it a whirl.
-
Adding Block Editor Commands to ribbon in CUI
SAFeSTeR replied to SAFeSTeR's topic in AutoCAD 2D Drafting, Object Properties & Interface
Ahhh, I didn't see the link, I'll check it out later. Thanks, I'm sure it will help. -
Adding Block Editor Commands to ribbon in CUI
SLW210 replied to SAFeSTeR's topic in AutoCAD 2D Drafting, Object Properties & Interface
Did you check the link I posted on customizing the Contextual tabs? You cannot add them to the Workspaces as they already activate when you open the block editor. -
Adding Block Editor Commands to ribbon in CUI
SAFeSTeR replied to SAFeSTeR's topic in AutoCAD 2D Drafting, Object Properties & Interface
Yes, similar to what you've shown but I'm unable to drag them to the 'Workspace Contents' on the right side of the CUI where I thought there would be a ribbon panel for block editor commands (there isn't one). I've found some block editor ribbon panels and dragged them across to my workspace but then these constantly show in the ribbon area and when I edit a block it adds a second. Now I have a conflict after closing the editor, the 'permanent' block editor ribbon panel is only showing the 'close block editor' command and when I click it I get a message saying it can only be used in the block editor. What I want to do is add commands to the ribbon shown in the 2nd image below -
If you don't mind sharing what else the code you have is doing or even better what you want it to do, this probably could be improved to coordinate with what you have already.
-
Adding Block Editor Commands to ribbon in CUI
SLW210 replied to SAFeSTeR's topic in AutoCAD 2D Drafting, Object Properties & Interface
Is this what your asking about? AFAIK this is only a Contextual tab, it would be there when opening the Block Editor custom workspace or not. All of my workspaces show an entry for the Ribbon tabs, but it only shows those regularly available, not any of the Contextual tabs, though LT may be limited in the CUI, I'm not sure. You should be able to customize it... Help | About Customizing Ribbon Contextual Tab States | Autodesk -
SAFeSTeR started following Adding Block Editor Commands to ribbon in CUI
-
Adding Block Editor Commands to ribbon in CUI
SAFeSTeR posted a topic in AutoCAD 2D Drafting, Object Properties & Interface
I can't figure out how to add commands to the block editor ribbon in my CUI file, specifically, the Parameters Manager. When I open my CUI and select my workspace there doesn't seem to be a ribbon section for the block editor, or at least I cannot find it. Can someone guide me to where it is please? Is it something to do with it being hidden until the block editor is active? -
Ashishsharmasoc joined the community
-
If you need to get data from a DWG drawing into Excel, you don’t have to do it manually. AutoCAD has a built-in Data Extraction tool that lets you grab all that object info and dump it right into a CSV or Excel sheet. It’s super handy for quickly throwing together things like bills of materials, block lists, or schedules.
-
Make it stop! autosaving in the middle of a command
rbshsnkar replied to MikeP's topic in AutoCAD General
I don't think there's a built-in setting that pauses AutoSave while a command is active. One thing that helped me was increasing the AutoSave interval slightly (for example, from 10 to 20 minutes), so it was less likely to interrupt longer commands while still keeping the protection of AutoSave. It might also be worth checking if any add-ins or background processes are delaying commands and making AutoSave more noticeable. -
rbshsnkar started following ACTCAD
-
rbshsnkar joined the community
-
I have been testing the python code by @Danielm103 and it works really well, the only hiccup is that you need to install Python on your pc plus load a couple of extra python modules. It is very straight forward to install. A more advanced version could produce what you have as a result. It's a simple task to remove columns from the outputted table.
- Yesterday
-
Sean J joined the community
-
I did think about doing a table...... I read the ctb by opening the ctb file and going to the table view. I will look at the above. Thanks!
-
riZwan joined the community
-
Shahdibraheem joined the community
-
Douglas Michel joined the community
-
Here is another for allowing explode... Solved: Re: Allow exploding outside the block editor - Autodesk Community Are these drawings from AutoCAD Civil 3D or some other CAD? (defun c:AllBlkYHtchN (/ ss i ent) (vl-load-com) ;;-------------------------------------------------- ;; Set Allow Exploding = Yes for all block definitions ;;-------------------------------------------------- (vlax-map-collection (vla-get-Blocks (vla-get-ActiveDocument (vlax-get-acad-object))) '(lambda (blk) (if (vlax-property-available-p blk 'Explodable) (vlax-put-property blk 'Explodable :vlax-true) ) ) ) ;;-------------------------------------------------- ;; Set all hatches Annotative = No ;;-------------------------------------------------- (if (setq ss (ssget "_X" '((0 . "HATCH")))) (progn (setq i 0) (repeat (sslength ss) (setq ent (ssname ss i)) (vl-catch-all-apply '(lambda () (setpropertyvalue ent "Annotative" 0) ) ) (setq i (1+ i)) ) ) ) (princ (strcat "\nUpdated " (itoa (if ss (sslength ss) 0)) " hatch(es). All explodable block definitions enabled." ) ) (princ) ) Do you need nested hatches and blocks, dynamic and/or anonymous blocks?
-
qscadservices joined the community
-
Just a comment in Bricscad V25 the setpropertyvalue does not work, the get does work. One of those odd bugs
-
EnM4st3r started following CAD Lisp Code Help
-
in autocad you could change Annotative to "No" using setpropertyvalue. For example: (setpropertyvalue ent "Annotative" 0)
-
Yet another block manager for BricsCAD
Danielm103 replied to Danielm103's topic in Application Beta Testing
Wonderful! Thanks for testing and for your valuable feedback! I'll add the carriage return after Insertion Point: I’m also considering making the rotation and scale options on screen, I’m still on the fence about that - Last week
-
Yet another block manager for BricsCAD
BIGAL replied to Danielm103's topic in Application Beta Testing
@Danielm103 has updated the code and its running under Bricscad and is very impressive, I am sure the updated code will be posted here soon.
