Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Is it possible to read the contents of a field with lisp?

8 REPLIES 8
Reply
Message 1 of 9
jefries1683
1340 Views, 8 Replies

Is it possible to read the contents of a field with lisp?

My goal involves the sheet set.  As far as I know sheet set manipulation is not possible with lisp, only with .NET.  However, I am simply trying to read one of the custom properties within a sheet set.  This can be done via fields.  Can a field then be read with lisp?

 

Thanks,

Jeff

8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: jefries1683
Message 3 of 9
jefries1683
in reply to: Anonymous

Thank you for the reply.

 

I did see this post in my searching, but it seems all solutions involve an entity of some sort - either a block to get a field from or an mtext to place a field into.

 

The field I am attemptint to work with is the SheetSet Custom Sheet property which I have named 'Released'.  If it does not contains a date I will have a "Preliminary" message appear on the title block.

 

So what I am getting at is this, if I do not have the field inserted within anything I cannot entget it.  Even if I did, can I translate it from the expression "%<\AcSm Sheet.Released>%" into something usable?

 

Thanks,

Jeff

Message 4 of 9
andrew.nao
in reply to: jefries1683

if you add the info to the custom dwg properties, you can read it. have you tried that?
Message 5 of 9
jefries1683
in reply to: andrew.nao

andrew.nao  How do you mean "you can read it"?

 

If I try something like (setq test (strcat  "%<\AcSm Sheet.Released>%"))  the result would be to assign the expression itself to 'test' rather than the contents of the field as I would like.

 

Is there something I am amissing?

 

Jeff

Message 6 of 9
Lee_Mac
in reply to: jefries1683

Jeff

 

AFAIK, you can't evaluate a field expression independent of an object. However, you could create a temporary MText object, populate its contents with the field expression, retrieve the value the field assumes, then delete the MText. That is, if the field is referencing something inaccessible through LISP - I have limited experience with Sheet Sets so I wouldn't know.

 

Lee

Message 7 of 9
andrew.nao
in reply to: jefries1683

well i dont use sheet sets but if i use %<\AcVar CreateDate \f "M/d/yyyy h:mm tt">% as a test it will display the date (obviously) so if you use

 

 

 

  (setq ent1 (ssget)) 

(setq ent (ssname ent1 0))

 (setq elist (entget ent))

 (setq x (cdr (assoc 1 elist)))

 

 

 it will set X to the current date you could then do what you want with the variable is this what you are looking to do?

Message 8 of 9
Lee_Mac
in reply to: Lee_Mac

A quick example for your consideration Jeff:

 

(defun EvalFieldString ( doc str / obj )
  (vl-cmdf "_.updatefield"
    (vlax-vla-object->ename
      (setq obj (vlax-invoke (vla-get-modelspace doc) 'addmtext '(0. 0. 0.) 0. str))
    )
    ""
  )
  (setq str (vla-get-textstring obj))
  (vla-delete obj)
  str
)

With some fields you may not need to use the UpdateField command:

 

(defun EvalFieldString ( doc str / obj )
  (setq obj (vlax-invoke (vla-get-modelspace doc) 'addmtext '(0. 0. 0.) 0. str))
  (setq str (vla-get-textstring obj))
  (vla-delete obj)
  str
)

 

Example call:

 

(setq doc (vla-get-activedocument (vlax-get-acad-object)))

(evalfieldstring doc "%<\\AcVar Date \\f \"MMMM d, yyyy\">%")
"August 9, 2011"

 Note the extra backslashes in the field string to mark the relevant characters as literals.

Message 9 of 9
jefries1683
in reply to: andrew.nao

Lee_Mac and andrew.nao - you guys are awesome.

 

I took your suggestions and put together a workable solution.

 

I started with Lee_Macs idea to create an mtext, populate it with the field and then extract it (which I didn't see how to do until andrews code example).  Then it occurred to me...

 

My goal is to find the 'released' attribute in a sheet.  I already had to verify that it is indeed a sheet in order to work.  If it is a sheet it will have a title block.  So rather than create a temporary mtext I am going to use the title block.  It already has an attribute with the field in it.

 

(IF (= (GETVAR "ssfound") "") ;_ check to see if there is a sheet set associated to the current file
    (COND ((SETQ titleblock (SSGET "X"
                                   (LIST (CONS 0 "insert")
                                         (CONS 2 "Anno-Ttlb-Engr-1117")
                                         (CONS 410 (GETVAR "ctab"))
                                   ) ;_ end of LIST
                            ) ;_ end of SSGET
           ) ;_ end of SETQ
           (SETQ listOatts     (MAPCAR
                                 '(LAMBDA (Att) (CONS (VLA-GET-TAGSTRING Att) (VLA-GET-TEXTSTRING Att)))
                                 (VLAX-INVOKE (VLAX-ENAME->VLA-OBJECT (SSNAME titleblock 0)) "GetAttributes")
                               ) ;_ end of MAPCAR
                 releasedVIAss (CDR (ASSOC "REL_DATE" listOatts))
           ) ;_ end of SETQ
          )
          ((SETQ titleblock (SSGET "X"
                                   (LIST (CONS 0 "insert")
                                         (CONS 2 "Anno-Ttlb-Engr-1824")
                                         (CONS 410 (GETVAR "ctab"))
                                   ) ;_ end of LIST
                            ) ;_ end of SSGET
           ) ;_ end of SETQ
           (SETQ listOatts     (MAPCAR
                                 '(LAMBDA (Att) (CONS (VLA-GET-TAGSTRING Att) (VLA-GET-TEXTSTRING Att)))
                                 (VLAX-INVOKE (VLAX-ENAME->VLA-OBJECT (SSNAME titleblock 0)) "GetAttributes")
                               ) ;_ end of MAPCAR
                 releasedVIAss (CDR (ASSOC "REL_DATE" listOatts))
           ) ;_ end of SETQ
          )
          ((SETQ titleblock (SSGET "X"
                                   (LIST (CONS 0 "insert")
                                         (CONS 2 "Anno-Ttlb-Engr-2436")
                                         (CONS 410 (GETVAR "ctab"))
                                   ) ;_ end of LIST
                            ) ;_ end of SSGET
           ) ;_ end of SETQ
           (SETQ listOatts     (MAPCAR
                                 '(LAMBDA (Att) (CONS (VLA-GET-TAGSTRING Att) (VLA-GET-TEXTSTRING Att)))
                                 (VLAX-INVOKE (VLAX-ENAME->VLA-OBJECT (SSNAME titleblock 0)) "GetAttributes")
                               ) ;_ end of MAPCAR
                 releasedVIAss (CDR (ASSOC "REL_DATE" listOatts))
           ) ;_ end of SETQ
          )
          ((SETQ titleblock (SSGET "X"
                                   (LIST (CONS 0 "insert")
                                         (CONS 2 "Anno-Ttlb-FPln-2436")
                                         (CONS 410 (GETVAR "ctab"))
                                   ) ;_ end of LIST
                            ) ;_ end of SSGET
           ) ;_ end of SETQ
           (SETQ listOatts     (MAPCAR
                                 '(LAMBDA (Att) (CONS (VLA-GET-TAGSTRING Att) (VLA-GET-TEXTSTRING Att)))
                                 (VLAX-INVOKE (VLAX-ENAME->VLA-OBJECT (SSNAME titleblock 0)) "GetAttributes")
                               ) ;_ end of MAPCAR
                 releasedVIAss (CDR (ASSOC "REL_DATE" listOatts))
           ) ;_ end of SETQ
          )
          (T ())
    ) ;_ end of COND
    (SETQ releasedVIAss nil) ;_ if no sheetset, then no auto-prelim
  ) ;_ end of if
  (IF (= releasedVIAss "####") ;_ if sheetset exists but sheet not release - then no auto-prelim
    (SETQ releasedVIAss nil)
  ) ;_ end of if

 

Then all there is to do is check with the releasedVIAss to see if the sheet is released before adding the 'Preliminary' note.

 

FYI, I realize that the redundant result of the COND is rather rediculous, but it works for now.

 

Thank you,

Jeff

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost