Jump to content

Copy Attribute Value as Field from Xref File


CAD_Noob

Recommended Posts

I need help. Do you guys have a working lisp that can copy the Attribute Value of a block in an xref file to a New Attribute Value in the Host file in Field Format?

so whenever the value of the attribute in the xref file changes, the value in the host file also changes.

 

 

Link to comment
Share on other sites

Cant get this working with fields inside of block. maybe the obj id is unique to the block/xref.

 

(defun c:TAG (/ att)
  (if (setq att (vla-fieldcode (vlax-ename->vla-object (car (nentsel "\nSelect Text with field data: ")))))
    (entmake 
      (list 
        (cons 0 "TEXT")
        (cons 10 (getpoint))
        (cons 40 (getvar 'DIMTXT))
        (cons 1  att)
      )
    )
  )
)

 

Edited by mhupp
Link to comment
Share on other sites

I dont think you can get a field the id is dwg dependant.

This is a block attribute

new dwg Xref obj ID 1742232416

original dwg obj ID 639756208

 

The only way may be to find the object in the other dwg and read its value  using say its handle and OBDX. Maybe xdata attached to the block.

 

Edited by BIGAL
Link to comment
Share on other sites

On 7/16/2022 at 10:29 PM, mhupp said:

Cant get this working with fields inside of block. maybe the obj id is unique to the block/xref.

 

(defun c:TAG (/ att)
  (if (setq att (vla-fieldcode (vlax-ename->vla-object (car (nentsel "\nSelect Text with field data: ")))))
    (entmake 
      (list 
        (cons 0 "TEXT")
        (cons 10 (getpoint))
        (cons 40 (getvar 'DIMTXT))
        (cons 1  att)
      )
    )
  )
)

 

 

Hi thanks for this...

just tested the routine.  

I want to select the item inside the xref (file 1) as an attribute  and copy the values to my drawing (file 2) as a field...

 

Link to comment
Share on other sites

10 minutes ago, CAD_Noob said:

I want to select the item inside the xref (file 1) as an attribute  and copy the values to my drawing (file 2) as a field...

 

Yes I understand, and it does that but the obj id is different between the xref and the drawing so it doesn't link to anything. You can use the command  on blocks or any field in the drawing and it works just fine. but when using it on a xref doesn't work.

Link to comment
Share on other sites

On 7/18/2022 at 10:52 AM, mhupp said:

 

Yes I understand, and it does that but the obj id is different between the xref and the drawing so it doesn't link to anything. You can use the command  on blocks or any field in the drawing and it works just fine. but when using it on a xref doesn't work.

 

I see.. so it is not possible?

 

Edited by CAD_Noob
typo
Link to comment
Share on other sites

42 minutes ago, CAD_Noob said:

 

I see.. so it it not possible?

 

 

I have come to realize that lisp can do quite a lot but their are limitations. I Don't know maybe? Their is always multiple ways to do things.

 

att = "%<\AcObjProp Object(%<\_ObjId 1167638480>%).Area>%"

attlst = ("%<\\AcObjProp Object(%<\\_ObjId " "1167638480" ">%).Area>%")

handle = "2F466"

when you run that through handnet it returns nil. this is further tested by opening the xref and testing for the handle on the same entity & it returns "2F466"

 

From what I have been reading you need a third data point like txt file or registry. to store the "string" data and then read that file into your current drawing.

But that seem clunky and messy.

 

Below code doesn't work on xref either.

(defun c:TAG (/ att attlst handle id)
  (setq att (vla-fieldcode (setq obj (vlax-ename->vla-object (car (nentsel "\nSelect Text with field data: "))))))
  (setq attlst (sepnumbers att))
  (setq handle (vla-get-handle (vla-objectidtoobject (vla-get-activedocument (vlax-get-acad-object)) (cadr attlst))))
  (setq str (strcat (car attlst) (rtos (vla-get-objectid (vlax-ename->vla-object (handent handle))) 2 0) (caddr attlst)))
  (entmake
    (list
      (cons 0 "TEXT")
      (cons 10 (getpoint))
      (cons 40 (getvar 'DIMTXT))
      (cons 1 str)
    )
  )
)
;https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-separe-number-and-string-in-the-same-string/m-p/2806136/highlight/true#M292581
(defun sepnumbers (str / tmp char currIsNr lastWasNr rslt)
  (setq tmp "")
  (while (/= (setq char (substr str 1 1)) "")
    (setq currIsNr (wcmatch char "#"))
    (if (eq currIsNr lastWasNr)
      (setq tmp (strcat tmp char))
      (setq rslt (cons tmp rslt)
            lastWasNr currIsNr
            tmp char
      )
    )
    (setq str (substr str 2))
  )
  (setq rslt (reverse (cons tmp rslt)))
  (cond
    ((not rslt) '( ""))
    ((eq (car rslt) "") (cdr rslt))
    (T rslt)
  )
)

 

  • Like 1
  • Agree 1
Link to comment
Share on other sites

  • 10 months later...

hello all, bumping this thread. 

As mention above I am using @Lee Mac CopySwap Text to copy the values of an attribute in an Xref File (Titleblock) to the value on an Attribute Block (Drawing Title)

 

It's working fine for single copy. 

 

Can it be modified so I can copy multiple values and add them into an attribute block as a single value?

Example : 

 

Source : 

Text1

Text2

Text3

 

Destination

Text2 - Text1, Text 3

 

If it can be copied as Field, it's much better

 

 

Edited by CAD_Noob
typo error
Link to comment
Share on other sites

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...