Set attribute value for windowed objects
I want to execute a command where I can do a crossing window and set (all included) attribute with tag BET1 to a defined value like ABCD, without further dialog.
Like:
Command
crossing window
enter
or crossing window
command
Howto, easiest?
Comments
-
You can do this via code. Maybe someone can translate this to Lisp
import traceback from pyrx_imp import Ap, Db, Ed, Ge, Gi, Gs, Rx print("added command = changeatt") def PyRxCmd_changeatt(): try: filter = [(Db.DxfCode.kDxfStart, "INSERT")] ps, ss = Ed.Editor.select(filter) refs = [Db.BlockReference(id) for id in ss.objectIds()] atts = [Db.AttributeReference(id) for ref in refs for id in ref.attributeIds()] for att in atts: if att.tag() == "BOXTYPE": att.upgradeOpen() att.setTextString("WOOHOO YES!") except Exception as err: traceback.print_exception(err)
0 -
Yep lisp exists, ok a question or 2, my way is a global function, select the attribute in a single block this returns Tagname & Blockname via code, so then ssget the blocks and change the correct attributes. Is this ok only one block name, if yes will post code done many times.
0 -
Name of block is always EPCBG1F0
Tag is always BET1
Value is always -XDA001
Value is sometime hidden (other attribute in block is visible)New value -XDA002
I need to mark those I want to change, some others need to be unchanged.
The idea is to do this without filling forms, like in Find and Replace.
0 -
Sorry another question is it just add 1 to last number ? This can be done.
0 -
Well, this is what I need just now but for a more common usage, I think edit value in LISP is better.
This is "one time job", but for many drawings.
0 -
Can you post a dwg please. Need to look at where block EPCBG1F0 is located Model, layouts etc or restrict changes some how. This may be a problem with multiple dwgs.
0 -
If you can figure out how to install python
Here’s a sample sledge hammer approach, that will change every attribute in a folder of .DWGs
https://github.com/CEXT-Dan/PyRx
import traceback from pyrx_imp import Rx, Ge, Gs, Gi, Db, Ap, Ed import wx import os, pathlib def changeit(db : Db.Database, tagValue, textValue): ids = db.objectIds(Db.AttributeReference.desc()) for att in [Db.AttributeReference(id) for id in ids]: if att.tag() == tagValue: att.upgradeOpen() att.setTextString(textValue) def openSideDrawing(path, tagValue,textValue): print("\nProcessing {} ".format(path)) db = Db.Database(False, True) db.readDwgFile(path) db.closeInput(True) changeit(db,tagValue,textValue) db.saveAs(path) def PyRxCmd_doit(): try: tagName = 'FGUIDE' textValue = 'WOOHOO YES!' dwgext = ".dwg".casefold() dlg = wx.DirDialog(None, "Choose input directory","", wx.DD_DEFAULT_STYLE | wx.DD_DIR_MUST_EXIST) if dlg.ShowModal() != wx.ID_OK: print("You Cancelled The Dialog!") return for fname in next(os.walk(dlg.GetPath()), (None, None, []))[2]: ext = pathlib.Path(fname).suffix.casefold() if ext != dwgext: continue fpath = '{}\\{}'.format(dlg.GetPath(),fname) openSideDrawing(fpath, tagName,textValue) print("yay") except Exception as err: traceback.print_exception(err)
0