get block name from anonymous block name (*U type blocks)

Hi.
I'm trying to get the effective block name from a parametric block,
for example - in the list I get *U22 where what I need is "PVC PIPE DN140 PN10 ID-129.2 BELL_DY".
I've made several attempts but failed.
I attached here a sample drawing and the lisp I have so far.

thanks,
aridzv.

Comments

  • Perhaps this post may help -
    Autodesk forum
  • hi Arid,
    try
    (setq instHandle (BmLispGet "Instance" ent))
    (setq instName (BmLispGet "InstanceName" instHandle))
    (print instName)
  • aridzv
    edited August 2023
    @Piet
    Hi and thanks for the reply.
    where in my lisp should I put this lines of code?

    thanks,
    aridzv.

    *EDIT:
    I put it in the repeat loop and I'm getting the *U names:
    NIL #GASKET 4In PN16_3d
    NIL #*U21
    NIL #*U22
    NIL #GASKET 4In PN16_3d
  • @JGAo1
    thanks,
    but no...
    that lisp select only *U type blocks and the effective names are uniq to each *U block...

    but thanks any way.
    aridzv.
  • aridzv
    edited August 2023
    @Jason Bourhill
    Hi.
    I saw this old post of yours.
    is there a way to use your code in my lisp?
    thanks,
    aridzv.
  • Its_Alive
    edited August 2023
    Not sure I understand the question. But if you just want the block name from the reference,
    This would be fairly easy in BRX or .NET. I’m using Python but the concept is the same

    def PyRxCmd_doit():
    try:
    filter = [(Db.DxfCode.kDxfStart, "INSERT")]
    ssResult = Ed.Editor.select(filter)
    if ssResult[0] != Ed.PromptStatus.eNormal:
    return

    for refid in ssResult[1].objectIds():

    #this is the "insert"
    blkref = Db.BlockReference(refid)

    #get the name from the BlockTableRecord
    btrrec = Db.BlockTableRecord(blkref.blockTableRecord())
    print(btrrec.getName())

    except Exception as err:
    print(traceback.format_exc())
    out

    GASKET 4In PN16_3d
    *U22
    *U21
    GASKET 4In PN16_3d
  • Hi @NigelTufnel.
    The problem I have is to get the block name (I.e. "PVC PIPE DN140 PN10 ID-129.2 BELL_DY")
    Instead of the *U21 and *U22...
  • Hi, that's not the name, but an attribute.
    I'm sure there's lots of lisp routines to get attributes

    def PyRxCmd_doit():
    try:
    filter = [(Db.DxfCode.kDxfStart, "INSERT")]
    ssResult = Ed.Editor.select(filter)
    if ssResult[0] != Ed.PromptStatus.eNormal:
    return

    for refid in ssResult[1].objectIds():
    blkref = Db.BlockReference(refid)

    for attid in blkref.attributeIds():
    att = Db.AttributeReference(attid)
    print("Tag = {}, Value = {}: ".format(att.tag(),att.textString()))

    except Exception as err:
    print(traceback.format_exc())


    Tag = ITEM_DESCRIPTION, Value = PVC PIPE DN140 PN10 ID-129.2 BELL:
    Tag = ORDER, Value = 2:
    Tag = QUANTITY, Value = 0.37:
    Tag = UNIT, Value = M:
    Tag = GRUOP, Value = PVC PIPES BELL:
    Tag = SYSTEM, Value = :
  • aridzv
    edited August 2023
    @NigelTufnel
    Hi.
    It is the block name,look in the sample dwg on the block name,
    Not the attribute "ITEM_DESCRIPTION"

    aridzv.
  • I see, I had opened the drawing in AutoCAD, snooping around in BricsCAD, I see a BDM_DATABASE attached. Not sure how to access that data. I’m guessing it contains a handle to the insert.

    Sorry about that


  • Asked at Cadtutor as well.
  • there's this
    https://developer.bricsys.com/bricscad/help/en_US/V23/DevRef/index.html

    (vl-load-mech)
    (mech:get-effectiveblocktablerecord (entget(car(entsel))))

    i get
    ; error : no function definition ; expected FUNCTION at [eval]

    maybe someone with mechanical can help
  • aridzv
    edited August 2023
    @NigelTufnel

    First of all I have to praise the Bricscad technical support and thank them for the help they gave me.
    without that help I would not have solved the problem.

    the way to get the effctive name of anonymous block (*U TYPE) in bricscad is:

    (setq bname (getpropertyvalue ent_n "EffectiveName~Native"))

    And here is a simple lisp that demonstrates it:
    (defun c:test ( / bname bname1 ensel obj )
    (vl-load-com)
       (setq ensel (entsel "\nSelect Block: ")) ;;select an anonymous block (*U TYPE) to get it's name
       (setq obj (car ensel)) ;;set the block object to an Entity name varaible
       (setq bname1 (vla-get-effectivename (vlax-ename->vla-object obj))) ;; get the *U name 
       (princ bname1)
       (setq bname (getpropertyvalue obj "EffectiveName~Native")) ;; get the effective name
    
       ;;(princ bname) ;; print the effective name
    )
    
    I also attched here the final lisp.
    regards,
    aridzv.
  • ALANH said:

    Asked at Cadtutor as well.

    yes,
    I did.
    and in one more place.
    and avuntually bricscad support solved it.