Jump to content

Recommended Posts

Posted (edited)

uses convertFieldToText

https://help.autodesk.com/view/OARX/2024/ENU/?guid=OARX-RefGuide-AcDbText__convertFieldToText

 

import traceback
from pyrx_imp import Rx
from pyrx_imp import Ge
from pyrx_imp import Gi
from pyrx_imp import Db
from pyrx_imp import Ap
from pyrx_imp import Ed
from pyrx_imp import Gs

# debug
def PyRxCmd_pydebug() -> None:
    import PyRxDebug
    PyRxDebug.startListener()

#converts fields to text for seleted refs
def PyRxCmd_fieldnuker5000() -> None:
    try:
        #modify filter
        filter = [(Db.DxfCode.kDxfStart, "INSERT")]
        ssres: tuple[Ed.PromptStatus,Ed.SelectionSet] = Ed.Editor.select(filter)
        if ssres[0] != Ed.PromptStatus.eOk:
            print("Oops {}: ".format(ssres[0])) 
            return
        
        for refid in ssres[1].objectIds():
            ref = Db.BlockReference(refid)
            for attid in ref.attributeIds():
                attref = Db.AttributeReference(attid,Db.OpenMode.kForWrite)
                if attref.hasFields():
                    attref.convertFieldToText()
                
    except Exception as err:
        traceback.print_exception(err)
   
#converts fields to text for named block
def PyRxCmd_fieldnuker9000() -> None:
    try:
        name = "Brdrtemplate" # getname
        
        db = Db.curDb()
        bt = Db.BlockTable(db.blockTableId())
        
        #find the block
        if not bt.has(name):
            return #oof
        btrid = bt.getAt(name)
        btr = Db.BlockTableRecord(btrid)
        
        #nuke em from orbit
        attdefids = btr.objectIds(Db.AttributeDefinition.desc())
        for attdefid in attdefids:
            attdef = Db.AttributeDefinition(attdefid,Db.OpenMode.kForWrite)
            if attdef.hasFields():
                attdef.convertFieldToText()
        
        for refid in btr.getBlockReferenceIds():
            ref = Db.BlockReference(refid)
            for attid in ref.attributeIds():
                attref = Db.AttributeReference(attid,Db.OpenMode.kForWrite)
                if attref.hasFields():
                    attref.convertFieldToText()
                
    except Exception as err:
        traceback.print_exception(err)
        

 

Edited by Danielm103
typo
  • Danielm103 changed the title to Convert Fields in blocks to text with Python

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...