Jump to content

Extract Field Code From Multileader Text


JackStone

Recommended Posts

Hello again.

 

I have made a lisp routine that creates multilines with text of the following format:

 

15NB%%C8.0c.20-356

 

The last number (after the dash) is a field linked to a polyline (object length divided by 10). I need to extract the object id from the field code.

 

In the past I used single-line text and I managed to extract the field code through vla-fieldcode, but that method is not available for multileaders and I can't find one to do the same.

 

So here is the problem: how do I extract the field code and, more specifically, the object id stored inside of it from a multileader text?

 

Thank you all for your time.

Link to comment
Share on other sites

This is one of those situations where the COM libraries haven't been extended sufficiently. Some would suggest you go through DotNet with this. But there is a pure AutoLisp method:

 

Say you have the mleader's ename in a variable called en:

(setq ed (entget en)) ;Get the multileader's DXF data list
(setq xdict (cdr (assoc 360 ed))) ;Get the ACAD-XDICTIONARY associated with the multilreader
(setq fdict (dictsearch xdict "ACAD_FIELD")) ;Get the Field dictionary associated with the multileader
(setq fdname (cdr (assoc -1 fdict))) ;Get the field dictionary's ename

From that you can step through each field-code attached into the ml's text using dictnext.

Link to comment
Share on other sites

Well, thank you very much! I shall try that out.

 

I don't know much about dictionaries. I see there seems to be a dictionary "inside" the entity which in turn stores other dictionaries (like "ACAD_FIELD"). Is that the correct perception? Where can I learn more about dictionaries?

 

Thank you again for your help!

Link to comment
Share on other sites

This was my function to retrieve the Field Expression:

 

;; Field Code  -  Lee Mac
;; Returns the field expression associated with an object.

(defun LM:FieldCode ( en / fd id )
   (cond
       (   (and
               (wcmatch (cdr (assoc 0 (setq en (entget en)))) "TEXT,MTEXT,ATTRIB")
               (setq en (cdr (assoc 360 en)))
               (setq en (dictsearch en "ACAD_FIELD"))
               (setq en (dictsearch (cdr (assoc -1 en)) "TEXT"))
               (setq fd (entget (cdr (assoc 360 en))))
           )
           (if (vl-string-search "\\_FldIdx " (cdr (assoc 2 en)))
               (vl-string-subst
                   (if (setq id (cdr (assoc 331 fd)))
                       (vl-string-subst
                           (strcat "ObjId " (itoa (vla-get-objectid (vlax-ename->vla-object id))))
                           "ObjIdx 0"
                           (cdr (assoc 2 fd))
                       )
                       (cdr (assoc 2 fd))
                   )
                   "\\_FldIdx 0"
                   (cdr (assoc 2 en))
               )
               (cdr (assoc 2 en))
           )
       )
   )
)
(vl-load-com)

Link to comment
Share on other sites

Thanks for that code, Lee! Exactly as it is it returns the fieldcode but the object Id is nowhere to be found. I don't understand exactly the meaning of "\\_FldIdx 0" that seems to be there in place of the Id.

 

I have made some changes to obtain the object the field is associated with. I'll post it here so that you can comment on it if you wish (and guide me in case I'm doing everything wrong :D):

 

(if (not (vl-catch-all-error-p
      (vl-catch-all-apply
        '(lambda (enlist)
       (setq ename
              (cdr
            (assoc
              331
              (entget
                (cdr
                  (assoc
                360
                (entget
                  (cdr
                    (assoc
                      360
                      (dictsearch
                    (cdr
                      (assoc
                        -1
                        (dictsearch
                          (cdr
                        (assoc
                          360
                          enlist
                        )
                          )
                          "ACAD_FIELD"
                        )
                      )
                    )
                    "TEXT"
                      )
                    )
                  )
                )
                  )
                )
              )
            )
              )
       )
         )
        (list (setq enlist (entget (car (entsel)))))
      )
    )
   )
 (progn
   (if    (= 'ENAME (type ename))
     (setq object (vlax-ename->vla-object ename))
   )
 )
)

Thank you all for your help once again!

Link to comment
Share on other sites

Well, thank you very much! I shall try that out.

 

I don't know much about dictionaries. I see there seems to be a dictionary "inside" the entity which in turn stores other dictionaries (like "ACAD_FIELD"). Is that the correct perception? Where can I learn more about dictionaries?

 

Thank you again for your help!

Hi, if you want to see what's inside dictionaries you could use my DictEdit routine. If you place both files in an ACad support folder and load the DictEdit.LSP you'll have 2 new commands (DictEdit and RawDisplay). The first shows all DWG-wide dictionaries (which has a Display button), the 2nd shows the raw DXF data of a selected entity. In both cases if you then double-click on an item in the list with an ename it opens another dialog displaying that item's DXF data.

 

This way you can obtain the links inside each and figure out how to get at them through assoc and/or dict***. You could use the Inspection tools in VLIDE, but I find they become a bit cumbersome when working with dictionaries.

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