Jump to content

Attribute to Object Field


CAD_Noob

Recommended Posts

hi, can somebody help me?

 

 

I want to select an attribute block and convert it to an Object Value field.

 

 

Currently my workflow is this :

Edit the attribute value

Highlight and select "Insert Field"

Under Field Category, I select Object

Under object type I pick which object I want the field to insert

Under Object Type properties, I select VALUE

on the Preview, I choose Uppercase.

 

 

wonder if this can be automated by just picking the attribute in the screen and convert it automatically to FIELD using Object Value.

 

 

Thanks in advance.

Link to comment
Share on other sites

I tried this one :

 

(defun c:test4 ( ) (LM:QuickField "Textstring" "%tc1" 1)) 

and I get an error:

 

Command: TEST4
Select Object with Textstring property:
Object does not have Textstring property.
Select Object with Textstring property:
Object does not have Textstring property.

I was selecting an Attribute tag that contains the value which I want to convert to field.

 

 

This is the field expression :

 %<\AcObjProp Object(%<\_ObjId 8796087809088>%).TextString \f "%tc1">%

Link to comment
Share on other sites

Oh, sorry you may need to change line 273 from:

                (list 'if '(setq ent (LM:quickfield:selectifhasprop prop entsel))

to:

                (list 'if '(setq ent (LM:quickfield:selectifhasprop prop nentsel))

The program will currently select the block reference when selecting an attribute within a block.

Link to comment
Share on other sites

Hi Lee, it's turning the attribute into a Field but appears as ####.

I've tried on several attribs and the result are the same. any thoughts why?

Link to comment
Share on other sites

;) just regenerate the drawing (type "_rga" at the commandline)

sysvar "fieldeval" may also be usefull

 

regards

Wolfgang

 

 

I did re-generate but still the same. Fieldeval is set to 31.

Link to comment
Share on other sites

  • 6 years later...
On 12/9/2017 at 5:22 AM, Lee Mac said:

You could use my Quick Field application to create a program which will allow you to accomplish this - please read the instructions provided on the program page and in the code header.

 

Just wanted to say thanks for this bit of code. 

 

I implemented it into my routine to swap out attributes in a detail cut for a hyperlink to other DWGs dynamically based on the attribute contents. Love it!

 

 

(vl-load-com)
(princ)




;; Get Attribute Value  -  Lee Mac
;; Returns the value held by the specified tag within the supplied block, if present.
;; blk - [vla] VLA Block Reference Object
;; tag - [str] Attribute TagString
;; Returns: [str] Attribute value, else nil if tag is not found.
(defun LM:vl-getattributevalue (blk tag)
  (setq tag (strcase tag))
  (vl-some '(lambda (att) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att)))
           (vlax-invoke blk 'getattributes))
)

; Function to extract project number based on the pattern ##-###
(defun LM:ExtractProjectNumber (path / i found)
  (setq i 0)
  (while (and (< i (- (strlen path) 6)) (not found))
    (if (and (>= (ascii (substr path (+ i 1) 1)) 48) (<= (ascii (substr path (+ i 1) 1)) 57)
             (>= (ascii (substr path (+ i 2) 1)) 48) (<= (ascii (substr path (+ i 2) 1)) 57)
             (= (substr path (+ i 3) 1) "-")
             (>= (ascii (substr path (+ i 4) 1)) 48) (<= (ascii (substr path (+ i 4) 1)) 57)
             (>= (ascii (substr path (+ i 5) 1)) 48) (<= (ascii (substr path (+ i 5) 1)) 57)
             (>= (ascii (substr path (+ i 6) 1)) 48) (<= (ascii (substr path (+ i 6) 1)) 57))
      (setq found (substr path (+ i 1) 6))
    )
    (setq i (+ i 1))
  )
  found
)

; Main function to update SHEETNUMBER fields in Detail Cut blocks
(defun C:UDN (/ dwgPath projectNumber)
  (setq dwgPath (getvar "DWGPREFIX"))
  (setq projectNumber (LM:ExtractProjectNumber dwgPath))
  (if projectNumber
    (LM:IterateBlocksAndUpdate "Detail Cut" projectNumber)
    (princ "\nUnable to extract project number from DWG path.")
  )
  (princ)
)

; Function to iterate over blocks named Detail Cut and update their SHEETNUMBER attributes
(defun LM:IterateBlocksAndUpdate (blockName projectNumber / doc blocks blk attribs attrib fieldCode sheetNumber)
  (setq doc (vla-get-activedocument (vlax-get-acad-object)))
  (setq blocks (vla-get-modelspace doc))
  (vlax-for blk blocks
    (if (and (= (vla-get-objectname blk) "AcDbBlockReference")
             (= (vla-get-effectivename blk) blockName))
      (progn
        (setq sheetNumber (LM:vl-getattributevalue blk "SHEETNUMBER"))
        (if (and sheetNumber (not (vl-string-search "X" sheetNumber)))
          (progn
            (setq fieldCode (strcat "%<\\AcVar \\href \".\\Structural  DETAILS-" projectNumber ".dwg#," sheetNumber " (24x36)#" sheetNumber "#1\">%"))
            (foreach attrib (vlax-invoke blk 'getattributes)
              (if (= (strcase (vla-get-tagstring attrib)) "SHEETNUMBER")
                (vla-put-textstring attrib fieldCode)
              )
            )
          )
        )
      )
    )
  )
  (command "regenall")
)

 

Edited by EYNLLIB
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...