LISP to update custom properties by pop list

LISP to update custom properties by pop list

Anonymous
Not applicable
2,602 Views
13 Replies
Message 1 of 14

LISP to update custom properties by pop list

Anonymous
Not applicable

Hi, I am trying to change the drawing properties custom field with a pop list provided below.

I have a functioning lisp and dcl file but I just can't get the drawing properties value to change in Autocad 2013 for an existing custom properties value when I select the ok button. Thanks for the Help.

 

( at bottom i have a code to change custom properties in Autocad but it is not linked to the name and address of the lisp.)

 

 

// DCL File to be saved as building.dcl

 

lbox : popup_list { width = 50; fixed_width = true; alignment = centered; }

 

building  : dialog { label ="Building"; spacer;

  : row {

    : lbox { key = "lst1"; label = "Name" ; }

    : lbox { key = "lst2"; label = "Address"; }

  }

  ok_only;

}

;;; I Know somting has to be changed with the ok_only button in the dcl just don’t know what???

 

 

;;; LISP

(defun c:building ( / *error* UpdateList data dclfile dclhandle )

 

  ;; Accompanying DCL File:

 

  (setq dclFile "building.dcl")

 

  (defun *error* ( msg )

 

    ;; Error Handler - will unload the dialog

    ;; from memory should the user decide to hit Esc

 

    (if dclHandle (unload_dialog dclHandle))

    (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")

        (princ (strcat "\n** Error: " msg " **")))

    (princ)

  )

 

  (defun UpdateList ( key lst )

 

    ;; This function updates the list_box associated with the specified key

    ;; using the contents of the supplied lst

 

    (start_list key)

    (mapcar 'add_list lst)

    (end_list)

  )

 

  ;; Data used to Populate List_Boxes:

 

  (setq Data

   '(  

("Tillson Nbr. 1  -             383         "              ("            120 Tillson,          Canton,                MA"))

("Tillson Nbr. 2  -             384         "              ("            121 Tillson,          Canton,                MA"))

("Tillson Nbr. 3  -             385         "              ("            122 Tillson,          Canton,                MA"))

("Tillson Nbr. 4  -             157         "              ("            123 Tillson,          Canton,                MA"))

("Tillson Nbr. 5  -             158         "              ("            124 Tillson,          Canton,                MA"))

("Tillson Nbr. 6  -             160         "              ("            135 Tillson,          Canton,                MA"))

      

    )

  )

 

  ;; Start of Main Routine

  ;; Lots of Error Trapping to make sure the Dialog Loads:

 

  (cond

    ( (<= (setq dclHandle (load_dialog dclFile)) 0)

 

      (princ "\n--> DCL File not Found.")

    )

    ( (not (new_dialog "building" dclHandle))

 

      (setq dclHandle (unload_dialog dclHandle))

      (princ "\n--> Dialog Definition not Found.")

    )

    ( t

      ;; Dialog Loaded Successfully.

 

      (or *Name*  (setq *Name*  "0"))

      (or *Address* (setq *Address* "0"))

 

      ;; Set up some default selections, for the first-time running of the program.

      ;; The variables *Name* & *Address* are intended to be global and hence will

      ;; remember the user's last selections.

 

      ;; Populate the List_Boxes:

 

      ;; List_Box 'lst1'

    

      (UpdateList "lst1" (mapcar 'car Data))

      (set_tile "lst1" *Name*)

 

      ;; List_Box 'lst2'

 

      (UpdateList "lst2" (cadr (nth (atoi *Name*) Data)))

      (set_tile "lst2" *Address*)

 

      ;; Action_tile Statements:

      ;; These control what happens when the user interacts with a tile in the dialog.

 

      (action_tile "lst1"

        (strcat

          "(UpdateList \"lst2\" (setq lst2 (cadr (nth (atoi (setq *Name* $value)) Data))))"

          "(setq *Address*"

          "  (set_tile \"lst2\""

          "    (if (< (atoi *Address*) (length lst2)) *Address* \"0\")"

          "  )"

          ")"

        )

      )

 

      ;; Here, when the user selects an item from 'lst1', the UpdateList subfunction

      ;; is fired to update the items in list_box 'lst2'.

 

      ;; list_box 'lst2' is also set to the value of *Address* if the index is

      ;; available for the selected item, else the first item is selected.

 

      ;; Note that $value is a string containg the index of the item

      ;; that the user has selected.

 

      (action_tile "lst2" "(setq *Address* $value)")

 

      ;; Dialog setup, lets start it:

 

      (start_dialog)

      (setq dclHandle (unload_dialog dclHandle))

    )

  )

  (princ)

)

 

 

Here is the code to change the drawing properties value, just need it to run when you select the  ok button.

 

(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object)))"PROJECT-NAME" "SUCCESS")

(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object)))"BLDG-ADDRESS" "SUCCESS")

0 Likes
Accepted solutions (2)
2,603 Views
13 Replies
Replies (13)
Message 2 of 14

dennis
Advisor
Advisor

I think you will need an OK button and a Cancel button in the DCL.

Setq a value to the button if clicked.

Check the value with an IF.

An example of this can be studied at:

https://knowledge.autodesk.com/support/autocad/troubleshooting/caas/discussion/t5/Visual-LISP-AutoLI...

 

0 Likes
Message 3 of 14

Anonymous
Not applicable

Hi Dennis

 

Thanks for your reply, All help is greatly appreciated . I will look into your reply, thanks again !!


The problem I am having is getting selected value from the pop list to update an existing custom drawing value in Autocad. I have 2 separate values I need

to get into Autocad when the ok button is selected.


I have building and address :


What I am looking for is some one to take the current code I supplied and get this working. Any ideas??

 

If some one could just code the building and address to fill in the custom properties i supplied when ok is selected?

 

 

0 Likes
Message 4 of 14

SeeMSixty7
Advisor
Advisor

Your command basically sets two variables to index values of the pull down lists.

 

*name* and *address*  *name* is the one you want to work off of I believe as this is the project number and then it sets the address pull down based on that selection. So the only index value you are concerned with is the *name* variable. Use that index value to grab the data from the data variable.

 

 

Try this just under (setq dclHandle (unload_dialog dcHandle))

 

(setq ProjectData (nth *name* data) ;Name returns an index value for the select list so we grab that from the data variable
           ProjectName (nth 0 ProjectData) ; this is the project name in the data list
           BldgAddress (nth 1 ProjectData) ; This is the address in the data list
      )
(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) ProjectName "SUCCESS")
(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) BldgAddress "SUCCESS")

 

 

Please note you have a lot of spaces for formatting in your data. I'm not sure that is the desired value you really want or not, but here you go.

 

Good luck

0 Likes
Message 5 of 14

Anonymous
Not applicable

Hi SeeMSixty7

 

Thank you for your help.

 

You are correct I am trying to fill in custom properties from selected list pick box selection. The building determines address.

 

 

Your command basically sets two variables to index values of the pull down lists. (YES)

 

*name* and *address*  *name* is the one you want to work off of I believe as this is the project number and then it sets the address pull down based on that selection. (YES) So the only index value you are concerned with is the *name* variable. Use that index value to grab the data from the data variable.

 

 

Try this just under (setq dclHandle (unload_dialog dcHandle))

 

(setq ProjectData (nth *name* data) ;Name returns an index value for the select list so we grab that from the data variable
           Project-Name (nth 0 ProjectData) ; this is the project name in the data list
           Bldg-Address (nth 1 ProjectData) ; This is the address in the data list
      )
(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) Project-Name "VALUE FROM SELECTED PICK BOX")
(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) Bldg-Address "VALUE FROM SELECTED PICK BOX")

 

 

Please note you have a lot of spaces for formatting in your data. I'm not sure that is the desired value you really want or not, but here you go.

 

Good luck

 

When i ran lisp it gave me a ** Error: bad argument type: fixnump ? A function requiring an integer argument has been passed an argument of incorrect data type with the value noted in the error message.

0 Likes
Message 6 of 14

SeeMSixty7
Advisor
Advisor

It looks like I misunderstood your key values.

 

I think this is what you are looking for at the end.

 

Assuming now that your key values are "PROJECT-NAME" and "BLDG-ADDRESS"

 

The variables set below will set the results from the pull down boxes in the dialog box.

 

(setq ProjectData (nth *name* data) 
           ProjectName (nth 0 ProjectData) 
           BldgAddress (nth 1 ProjectData) 
)

 

The ProjectName variable now holds the text from the Project Drop Down list

The BldgAddress variable now holds the text from the Address drop down list

 

Now use the following to set your CustomKey values.

 

(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) "PROJECT-NAME" ProjectName)
(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) "BLDG-ADDRESS" BldgAddress)

 

Hope that works for you.

0 Likes
Message 7 of 14

Anonymous
Not applicable

Hi SeeMSixty7

 

Thank you for your help.

 

I think we are very close now!

 

I am getting a ** Error: bad argument type: fixnump: "0" **        ( 0 being the first item on the list.)

0 Likes
Message 8 of 14

SeeMSixty7
Advisor
Advisor

Sorry I forgot your index was a string Try this

 

(setq ProjectData (nth (atoi *name*) data) ;Name returns an index value for the select list so we grab that from the data variable
           ProjectName (nth 0 ProjectData) ; this is the project name in the data list
           BldgAddress (nth 1 ProjectData) ; This is the address in the data list
      )
      (vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object)))ProjectName "SUCCESS")
      (vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object)))BldgAddress "SUCCESS")

0 Likes
Message 9 of 14

Anonymous
Not applicable

 

Hi SeeMSixty7

 

Thank you for your help!!!

 

The building name is working, But when the program tries to complete the address error below is displayed.

 

 

** Error: lisp value has no coercion to VARIANT with this type: (" 135 Tillson, Canton, MA") **

 

 

0 Likes
Message 10 of 14

SeeMSixty7
Advisor
Advisor

It looks like your address item is stored as a list in your data variable. I didn't notice that before.

 

 

update the line below

 

BldgAddress (nth 1 (car ProjectData))

 

Hopefully that does the trick, grin.

0 Likes
Message 11 of 14

Anonymous
Not applicable

Hi SeeMSixty7

 

Thank you for your help!!!

 

** Error: bad argument type: consp "Tillson Nbr. 1 - 383" **

 

 

If I preformed the correct EDIT below???

 

(start_dialog)

(setq dclHandle (unload_dialog dclHandle))

)

)
(setq ProjectData (nth (atoi *name*) data) ;Name returns an index value for the select list so we grab that from the data

variable
ProjectName (nth 0 ProjectData) ; this is the project name in the data list
BldgAddress (nth 1 (car ProjectData)) ; This is the address in the data list
)

(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) "PROJECT-NAME" ProjectName)
(vla-SetCustomByKey(vla-get-summaryinfo(vla-get-activedocument(Vlax-get-acad-object))) "BLDG-ADDRESS" BldgAddress)

(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acAllViewports)
(princ)
)

0 Likes
Message 12 of 14

SeeMSixty7
Advisor
Advisor
Accepted solution

DOH!

 

My bad.

 

(setq ProjectData (nth (atoi *name*) data) ;Name returns an index value for the select list so we grab that from the data variable
         ProjectName (nth 0 ProjectData) ; this is the project name in the data list
         BldgAddress (car (nth 1 ProjectData)) ; This is the address in the data list

)

 

Let me know. We have to be getting close. LOL

0 Likes
Message 13 of 14

Anonymous
Not applicable
Accepted solution

Hi SeeMSixty7

 

Thank you for your help!!!

 

Brilliant you did it!!!

Great Job!!!

0 Likes
Message 14 of 14

SeeMSixty7
Advisor
Advisor

Sweet!

 

Glad it worked out.

 

Enjoy and have a great day!

0 Likes