See the top rated post in this thread. Click here

Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Updating Lisp Variable

  1. #1
    Member
    Join Date
    2006-09
    Posts
    21
    Login to Give a bone
    0

    Default Updating Lisp Variable

    I created a Lisp mainly so I can link a field to a lisp variable. Everything works fine except that I need to run the lisp everytime the variable changes. For example, I created a lisp to count the layouts in the drawing. Eveytime I add a layout, I need to run the lisp again to recount. Anyway to have the field/lisp variable to update everytime a layout is added?

  2. #2
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    You can with code.

    Code:
    (defun AddObjectField (AddToEname LinkObj PropName / EntData ExDict FDict PropType PropValue)
        (if
            (and
                (setq EntData (entget AddToEname))
                (vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
                (setq ExDict
                    (vlax-vla-object->ename
                        (vla-GetExtensionDictionary
                            (vlax-ename->vla-object AddToEname)
                        )
                    )
                )
                (setq PropType
                    (type
                        (setq PropValue
                            (vlax-get LinkObj PropName)
                        )
                    )
                )
            )
            (progn
                (dictremove ExDict "ACAD_FIELD")
                (setq FDict
                    (dictadd ExDict "ACAD_FIELD"
                        (entmakex
                            '(
                                (0 . "DICTIONARY")
                                (100 . "AcDbDictionary")
                                (280 . 1)
                                (281 . 1)
                            )
                        )
                    )
                )
                (dictadd FDict "TEXT"
                    (entmakex
                        (list
                            '(0 . "FIELD")
                            '(100 . "AcDbField")
                            '(1 . "_text")
                            '(2 . "%<\\_FldIdx 0>%")
                            '(90 . 1) ;Number of child fields
                            (cons 360 ;Child field ID
                                (entmakex
                                    (list
                                        '(0 . "FIELD")
                                        '(100 . "AcDbField")
                                        '(1 . "AcObjProp") ; Field type
                                        (cons
                                            2
                                            (strcat
                                                "\\AcObjProp Object(%<\\_ObjIdx 0>%)."
                                                PropName
                                            )
                                        )
                                        '(90 . 0) ; Number of child fields
                                        '(97 . 1) ; Number of object ids
                                        (cons 331 (vlax-vla-object->ename LinkObj)) ; Object id
                                        '(4 . "") ; format string
                                        '(91 . 63) ; evaluation option
                                        '(92 . 0) ; filling option
                                        ;'(94 . 59) ; field state flag
                                        ;'(95 . 2) ; evaluation status
                                        ;'(96 . 0) ; evaluation error code
                                        ;'(300 . "") ; evaluation error message
                                        '(6 . "ObjectPropertyId")
                                        '(90 . 64)
                                        (cons 330 (vlax-vla-object->ename LinkObj))
                                        '(6 . "ObjectPropertyName") ; key string for the field data
                                        '(90 . 4) ; data type of field
                                        (cons 1 PropName) ; name of property
                                        '(7 . "ACAD_FIELD_VALUE") ; key string for the evaluated cache
                                        (cons
                                            90 ;data type of field
                                            (cond
                                                ((equal PropType 'STR)
                                                    4
                                                )
                                                ((equal PropType 'INT)
                                                    1
                                                )
                                                ((equal PropType 'REAL)
                                                    2
                                                )
                                                ((equal PropType 'LIST)
                                                    32
                                                )
                                            )
                                        )
                                        (cond ; field value
                                            ((equal PropType 'STR)
                                                (cons 1 PropValue)
                                            )
                                            ((equal PropType 'INT)
                                                (cons 91 PropValue)
                                            )
                                            ((equal PropType 'REAL)
                                                (cons 140 PropValue)
                                            )
                                            ((equal PropType 'LIST)
                                                (cons 11 Propvalue)
                                            )
                                        )
                                        '(300 . "") ; format string for '08
                                        '(301 . "") ; format string
                                        '(98 . 0) ; length of format string
                                    )
                                )
                            )
                            '(97 . 0) ; Number of object IDs used in the field code
                            '(4 . "") ; Format string
                            '(91 . 63) ; Evaluation option
                                ;kDisable 0 Disable evaluation. 
                                ;kOnOpen (0x1 << 0) Evaluate during drawing load. 
                                ;kOnSave (0x1 << 1) Evaluate during drawing save. 
                                ;kOnPlot (0x1 << 2) Evaluate during drawing plot. 
                                ;kOnEtransmit (0x1 << 3) Evaluate during eTransmit. 
                                ;kOnRegen (0x1 << 4) Evaluate during regen. 
                                ;kOnDemand (0x1 << 5) Evaluate only on demand by the user or the API. 
                                ;kAutomatic (kOnOpen | kOnSave | kOnPlot | kOnEtransmit | kOnRegen | kOnDemand) Automatically evaluate fields during all the operations. 
                            '(92 . 0) ;Filling option
                                ;kSkipFilingResult (0x1 << 0) Do not file out the cached evaluation result with the field. 
                            ;'(94 . 5) ;Field state flag
                                ;kInitialized (0x1 << 0) Field is not yet intitalized with any field code or data. 
                                ;kCompiled (0x1 << 1) Field has been compiled. 
                                ;kModified (0x1 << 2) Field has been modified and not yet evaluated. 
                                ;kEvaluated (0x1 << 3) Field has been evaluated. Use evaluationStatus() to get the evaluation status. 
                                ;kHasCache (0x1 << 4) The field has a cache of the evaluated result. 
                                ;'(95 . 1) ;Evaluation status
                                ;kNotYetEvaluated (0x1 << 0) Field is not yet evaluated. 
                                ;kSuccess (0x1 << 1) Field is evaluated successfully. 
                                ;kEvaluatorNotFound (0x1 << 2) Evaluator was not found. 
                                ;kSyntaxError (0x1 << 3) Syntax error in the field expression. 
                                ;kInvalidCode (0x1 << 4) Invalid field code or expression. 
                                ;kInvalidContext (0x1 << 5) Current context is invalid for evaluating the field. 
                                ;kOtherError (0x1 << 6) Evaluation has failed. 
                            ;'(96 . 0) ;Evaluation error code
                            ;'(300 . "") ;Evaluation error message
                            '(93 . 1) ;Number of the data set in the field
                            '(6 . "ACFD_FIELDTEXT_CHECKSUM") ;Key string for field data
                            '(90 . 2) ;Data type of field value
                            '(140 . 33.0) ;Double value
                            '(7 . "ACFD_FIELD_VALUE") ;Key string from the evaluated cache, hard coded as is shown here
                            '(90 . 0) ;Data type of field value
                            '(91 . 0) ;Long value
                            '(301 . "") ; format string
                            '(98 . 0) ; format string length
                        )
                    )
                )
                (entupd AddToEname)
            )
        )
    )
    Then select the mtext you want, with this code to run ( after you have loaded the above code ).

    Code:
    (AddObjectField
        (car (entsel "\n Select mtext entity: "))
        (vla-get-Layouts (vla-get-ActiveDocument (vlax-get-Acad-Object)))
        "Count"
    )

  3. #3
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    So did it work?

    Did you try?

    Am I providing answers to nobody?

  4. #4
    Member
    Join Date
    2006-09
    Posts
    21
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    Sorry. Just looked at the response now. I'm very new to writing lisp so that's a whole lot of code to take in. I'll try to implement it and let you know what happens

  5. #5
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    Quote Originally Posted by sam.121498 View Post
    Sorry. Just looked at the response now. I'm very new to writing lisp so that's a whole lot of code to take in. I'll try to implement it and let you know what happens
    All good. It took a lot of research to do that code, so I understand how you feel. I just like to know if my stuff helps people out is all. I hope you can understand it, and learn from it, and I hope it does work for you.

    I can try and tell you what is happening, if that helps you out. Let me know.

  6. #6
    100 Club
    Join Date
    2005-09
    Posts
    111
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    Quote Originally Posted by T.Willey View Post
    All good. It took a lot of research to do that code, so I understand how you feel. I just like to know if my stuff helps people out is all. I hope you can understand it, and learn from it, and I hope it does work for you.

    I can try and tell you what is happening, if that helps you out. Let me know.
    Sorry,

    I get with AddObjectField : "Error: no function definition: VALUE"

    Regards, HofCAD CSI.

  7. #7
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    Same here.
    Code:
     (defun AddObjectField (AddToEname LinkObj PropName / EntData ExDict FDict PropType PropValue)
        (if
            (and
                (setq EntData (entget AddToEname))
                (vl-position (value 0 EntData) '("MTEXT" "ATTRIB" "ATTDEF"))
    Code looks pretty cool though. I'd like to see it modify a custom property like "pages" that all my layouts have a field referencing.

  8. #8
    AUGI Addict
    Join Date
    2005-08
    Posts
    1,043
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    Quote Originally Posted by hofcad View Post
    Sorry,

    I get with AddObjectField : "Error: no function definition: VALUE"

    Regards, HofCAD CSI.
    Sorry about that. Dang small helper functions.

    Code:
    (defun VALUE (num ent /)
    	(cdr (assoc num ent))
    )
    I don't know if I understand Tom. I don't use custom properties, and I'm not sure if you can use that with my code, as that is something with the drawing right? I don't think you can get a document property to use with this, but I haven't really tried either. I don't use fields. This was more of a learning experience.

  9. #9
    Active Member
    Join Date
    2002-12
    Posts
    77
    Login to Give a bone
    1

    Thumbs up Re: Updating Lisp Variable

    Tom,

    You can try some of this code. (Not sure where it came from) but this should do what you want it to.

    Code:
    (defun C:addprops1 (/ App Doc DwgProps lanme dname pname)
    
    	(setq app (vlax-get-acad-object))
    	(setq doc (vla-get-activedocument app))
    	(setq dwgprops (vla-get-summaryinfo doc))
    
      (setq lname (getvar "loginname"))
      (setq dname (vl-filename-base (getvar "dwgname")))
      (setq	pname (vl-filename-base	(vl-filename-directory (getvar "Dwgprefix"))))
    	
      (if (vl-catch-all-apply	'vla-removecustombykey (list dwgprops "Job No."))
        (vla-addcustominfo dwgprops "Job No." pname)
        (progn
          (vl-catch-all-apply	'vla-removecustombykey	(list dwgprops "Job No."))
          (vla-addcustominfo dwgprops "Job No." pname)
        )
      )
      (if (vl-catch-all-apply	'vla-removecustombykey	(list dwgprops "DWG Name"))
        (vla-addcustominfo dwgprops "DWG Name" dname)
        (progn
          (vl-catch-all-apply	'vla-removecustombykey	(list dwgprops "DWG Name"))
          (vla-addcustominfo dwgprops "DWG Name" dname)
        )
      )
    
    	(vla-put-title dwgprops "Title2")
    	(vla-put-revisionNumber dwgprops "666")
    	(vla-put-subject dwgprops "Subject")
    	(vla-put-author dwgprops "The Man The Myth The Legend")
    	(vla-put-keywords dwgprops "A Few Keywords")
    	(vla-put-comments dwgprops (strcat "Comment 1\r\n" "comment 2\r\n" "comment 3\r\n"))
    	;(vla-put-comments dwgprops "This is a comment.  Comments can not be seperated by lines")
    	(vla-put-hyperlinkbase dwgprops "http://ScrewYou.com")	
    	
    	(setq SavedBy (vla-get-LastSavedBy dwgprops))
    	
    	(princ)
    )

  10. #10
    Certifiable AUGI Addict
    Join Date
    2001-03
    Location
    Tallahassee, FL USA
    Posts
    3,667
    Login to Give a bone
    0

    Default Re: Updating Lisp Variable

    Quote Originally Posted by T.Willey View Post
    Sorry about that. Dang small helper functions.

    Code:
    (defun VALUE (num ent /)
        (cdr (assoc num ent))
    )
    I don't know if I understand Tom. I don't use custom properties, and I'm not sure if you can use that with my code, as that is something with the drawing right? I don't think you can get a document property to use with this, but I haven't really tried either. I don't use fields. This was more of a learning experience.
    Thanks, that code did the trick. I can modify it to modify the custom properties.

Page 1 of 2 12 LastLast

Similar Threads

  1. Force Screen Updating while LISP running
    By mailmaverick361505 in forum AutoLISP
    Replies: 5
    Last Post: 2013-12-12, 06:28 PM
  2. Autocad version variable in a lisp?
    By gilsoto13 in forum AutoLISP
    Replies: 3
    Last Post: 2009-08-06, 08:52 PM
  3. Updating multiple computers using a script or LISP file
    By Chris.Partin in forum AutoCAD Customization
    Replies: 9
    Last Post: 2007-08-22, 04:34 PM
  4. Maintaining a lisp variable between sessions
    By anderson.scottglen in forum AutoLISP
    Replies: 3
    Last Post: 2007-07-16, 08:13 PM
  5. Help updating a wall LISP
    By tflaherty in forum AutoLISP
    Replies: 5
    Last Post: 2005-08-02, 08:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •