All Activity
- Past hour
-
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)) # ]
- Today
-
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. -
Have a look at this
-
hafizmesut10 joined the community
-
lapot89 joined the community
-
Danielm103 started following Python, read CTB files
-
seems ezdxf has this feature, so we can just use it. import wx from ezdxf.addons import acadctb from pyrx import Ap, Db, Ed def browse_for_ctb(): """Opens a native wxPython file dialog to browse for a CTB file.""" parent = wx.GetApp().GetTopWindow() with wx.FileDialog( parent, "Select AutoCAD CTB File", wildcard="CTB files (*.ctb)|*.ctb", style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST, ) as fileDialog: if fileDialog.ShowModal() == wx.ID_CANCEL: return None return fileDialog.GetPath() @Ap.Command() def doit() -> None: ctb_path = browse_for_ctb() if not ctb_path: print("\nCommand cancelled.") return try: # 2. Parse the CTB using ezdxf ctb_data = acadctb.load(ctb_path) except Exception as e: print(f"\nFailed to parse CTB file: {str(e)}") return active_colors = [] for idx in range(1, 256): style = ctb_data[idx] # Keep the entry if it overrides lineweight or screening if style.lineweight >= 0 or style.screen < 100: # Store the index along with the full style object to access all 10 properties active_colors.append((idx, style)) if not active_colors: print("\nNo explicit pen styles overrides found in this CTB. Table skipped.") return db = Db.curDb() ps, insert_pt = Ed.Editor.getPoint("\nSpecify insertion point for the CTB table: ") if ps != Ed.PromptStatus.kNormal: return table = Db.Table() table.setDatabaseDefaults(db) # 10 headers corresponding to all the available style properties headers = [ "ACI Index", "Lineweight", "Screening", "Dither", "Phys Pen", "Virt Pen", "Linetype", "Adaptive LT", "Fill Style", "Style Index" ] total_rows = len(active_colors) + 2 # Title row + Header row + Data rows table.setSize(total_rows, len(headers)) table.setPosition(insert_pt) table.generateLayout() # Title Row Configurations table.setTextString(0, 0, f"Complete CTB Profile: {ctb_path.split('\\')[-1]}") # Header Row Configurations for col_idx, header_text in enumerate(headers): table.setTextString(1, col_idx, header_text) # Populate Data rows for row_idx, (idx, style) in enumerate(active_colors, start=2): lweight_str = f"{style.lineweight:.2f} mm" if style.lineweight >= 0 else "Use Object Value" table.setBackgroundColor(row_idx, 0, Db.Color(style.aci)) table.setContentColor(row_idx, 0, Db.Color(7)) table.setTextString(row_idx, 0, str(style.aci)) table.setTextString(row_idx, 1, lweight_str) table.setTextString(row_idx, 2, f"{style.screen}%") table.setTextString(row_idx, 3, "On" if style.dithering == 1 else "Off") table.setTextString(row_idx, 4, str(style.physical_pen_number)) table.setTextString(row_idx, 5, str(style.virtual_pen_number)) table.setTextString(row_idx, 6, str(style.linetype)) table.setTextString(row_idx, 7, "Yes" if style.adaptive_linetype == 1 else "No") table.setTextString(row_idx, 8, str(style.fill_style)) table.setTextString(row_idx, 9, str(style.index)) db.addToCurrentspace(table) print(f"\nSuccessfully generated a 10-column table with {len(active_colors)} CTB overrides.")
-
- 1
-
-
Forum upgrade to Invision Community 5
CADTutor replied to CADTutor's topic in News, Announcements & FAQ
UPDATE: There has been a delay in the forum upgrade. I will make a further announcement in due course and let you know when it will be happening.- 1 reply
-
- 1
-
-
Here is a quick find from Google for setting all blocks as explodable: ;; Set every block as explodable ;; http://forums.augi.com/showthread.php?33008-Allow-block-exploding&highlight=explodable&pp=10 ;; posted by whdjr (defun c:eb () (vl-load-com) (vlax-map-collection (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)) ) '(lambda (x) (and (vlax-property-available-p x 'explodable) (eq (vlax-get-property x 'explodable) :vlax-false) (not (vlax-put-property x 'explodable :vlax-true)) ) ) ) )
-
nymph joined the community
-
Make it stop! autosaving in the middle of a command
SLW210 replied to MikeP's topic in AutoCAD General
I know Autosave was around since release 11 in 1990, 36 years and pretty much stayed the same and as per the OP, occurs in the middle of a command, I do not believe this behavior will change anytime soon. Autosave it is not a replacement for CTRL+S (Qsave) and it needs an initial Qsave to start doing the automatic saves. For those that use this feature... https://www.autodesk.com/support/technical/article/caas/sfdcarticles/sfdcarticles/Understanding-AutoCAD-backup-and-autosave-files.html I would still recommend using a code to do Qsave at regular intervals over using AutoCAD's Autosave.
