Inserting text into an existing table with AutoLisp

Inserting text into an existing table with AutoLisp

cdmiske
Enthusiast Enthusiast
3,471 Views
17 Replies
Message 1 of 18

Inserting text into an existing table with AutoLisp

cdmiske
Enthusiast
Enthusiast

Hello all. I am working on developing a dialog menu to fill in a table for me using check boxes. The objective for each check box is if set to true it will add a Wingding 0xFC ascii code. I have been able to fully flesh out the the dialog box. Being that I am still a novice I am  having some trouble with understanding how to approach filling in this table. I am in need of some guidance.

 

I know that I will need to add in an if statement to each action tile that will either add in the wingding check to a specific cell location for each checkbox. So far I am still reading up on how to do that through several forum discussions and tutorials.

 

MY first question is do I need to select the existing table before executing the dialog to associate to the table I need filled in?

 

Second question is if it is possible to access the table without needing to select it first? I am hoping to tie this into other tables i.e. a responsibility matrix table for the contractor.

 

This is new grounds for me currently with only limited experience in making simple routines before. Want to try to start developing more complex functions that do more of the repetitive work or improve consistency for me.

 

Dialog:

Opt_Menu : dialog {			//dialog name

	label = "Options List" ;	//pop-up window title

	:boxed_radio_column {

		label = "Interior Options" ;


		: row {

			: toggle {key = "t1" ; label = "New static menu board" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: toggle {key = "t8" ; label = "New New ceiling tiles" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: toggle {key = "t15" ; label = "Separate order/pay from pick-up" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: toggle {key = "t21" ; label = "Replace window sills W/ solid surface" ; width = 40; edit_width = 35; fixed_width = true; alignment = left;}

		}

		: row {

			: toggle {key = "t2" ; label = "New static queuing board" ; width = 32;  edit_width = 30; fixed_width = true; alignment = left;}
			: toggle {key = "t9" ; label = "New ceiling grid" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: toggle {key = "t16" ; label = "New 2x4 ligths in dining area" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: toggle {key = "t22" ; label = "Replace servicd counter back wall finishes" ; width = 40; edit_width = 35; fixed_width = true; alignment = left;}

		}

		: row {

	 		: toggle {key = "t3" ; label = "New static RHR" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
	 		: toggle {key = "t10" ; label = "New pendant lights" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
	 		: toggle {key = "t17" ; label = "Replace restroom finishes" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}

	 	}

	 	: row {

	 		: toggle {key = "t4" ; label = "Self-serve drink - one freestyle" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
	 		: toggle {key = "t11" ; label = "Artpack" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
	 		: toggle {key = "t18" ; label = "Replace restroom fixtures" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}

	 	}

	 	: row {

	  		: toggle {key = "t5" ; label = "Condiment stand" ; width = 32;  edit_width = 30; fixed_width = true; alignment = left;}
	  		: toggle {key = "t12" ; label = "WiFi service" ; width = 32; edit_width = 30; fixed_width = true; alignment = center;}
	  		: toggle {key = "t19" ; label = "Freestyle in drive-thru" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}

	  	}

	  	:row {

	  		: toggle {key = "t6" ; label = "New drink stand (small, plumbed)" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
	  		: toggle {key = "t13" ; label = "All wood look porcelain plank tile" ; width = 32; edit_width = 30; fixed_width = true; alignment = center;}
	  		: toggle {key = "t20" ; label = "New wall tile in drive-thru" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}

	  	}

	  	: row {

	   		: toggle {key = "t7" ; label = "New drink stand (large, plumbed)" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
	   		: toggle {key = "t14" ; label = "Music W/ ceilng mounted speakers" ; width = 32; edit_width = 30; fixed_width = true; alignment = center;}
			: spacer {width = 32; edit_width = 30; fixed_width = true; alignment = left;}
			: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}

	   	}
	}

	: row {

		:boxed_radio_column {

		label = "Exterior Options" ;


			: row {

				: toggle {key = "t23" ; label = "New building signage" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t24" ; label = "PUW vestibule" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t25" ; label = "Pre-order menu" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
				: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}

			}

			: row {

				: toggle {key = "t26" ; label = "Remove directional signs" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t27" ; label = "Blade wall branding" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: spacer {width = 32; edit_width = 30; fixed_width = true; alignment = left;}
				: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}

			}

			: row {

				: toggle {key = "t28" ; label = "Landscaping" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t29" ; label = "Tag branding" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: spacer {width = 32; edit_width = 30; fixed_width = true; alignment = left;}
				: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}
			
			}

			: row {

				: toggle {key = "t30" ; label = "New architectural metal panels" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t31" ; label = "Canopy at pay window" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: spacer {width = 32; edit_width = 30; fixed_width = true; alignment = left;}
				: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}
			
			}

			: row {

				: toggle {key = "t32" ; label = "Paint (E) wall sconces" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t33" ; label = "Canopy at pick-up window" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: spacer {width = 32; edit_width = 30; fixed_width = true; alignment = left;}
				: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}
	
			}

			: row {

				: toggle {key = "t34" ; label = "New wall sconces" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t35" ; label = "Canopy of order station at DT" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: spacer {width = 32; edit_width = 30; fixed_width = true; alignment = left;}
				: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}
	
			}

			: row {

				: toggle {key = "t36" ; label = "Paint (E) storefront" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: toggle {key = "t37" ; label = "Clearance bar" ; width = 32; edit_width = 30; fixed_width = true; alignment = left;}
		 		: spacer {width = 32; edit_width = 30; fixed_width = true; alignment = left;}
				: spacer {width = 40; edit_width = 35; fixed_width = true; alignment = left;}
	
			}
		}

	}
	     
	ok_cancel ;			//predefined Ok/Cancel Buttons

	: row {				//defines row

	: paragraph {			//adding text at bottom of dialog

	: text_part {			//define first line of text
	label = "Developed by:";	//first line of text
	}				//end first line of text

	: text_part {			//define second line of text
	label = "Chris Miske";		//second line of text
	}				//end second line of text

    }					//end paragraph

  }					//end of row
	
}					//end dialog

 

Function:

(defun C:Opt_List ()					;defines the function

  (setq dcl_id (load_dialog "Opt_Menu"))		;loads the dialog box "pop-up menu"

  (if (not (new_dialog "Opt_Menu" dcl_id))		;if statement to exit if the .dcl file is not found

(princ "\n** DCL File not Found **")	  		;exits functiop with error message

)							;end if statement

  (action_tile "t1" "(setq hole \"menu\")")
  (action_tile "t2" "(setq hole \"queuing\")")
  (action_tile "t3" "(setq hole \"RHR\")")
  (action_tile "t4" "(setq hole \"freestyle\")")
  (action_tile "t5" "(setq hole \"condiment\")")
  (action_tile "t6" "(setq hole \"drink_small\")")
  (action_tile "t7" "(setq hole \"drink_large\")")
  (action_tile "t8" "(setq hole \"ceiling_tiles\")")
  (action_tile "t9" "(setq hole \"ceiling_grid\")")
  (action_tile "t10" "(setq hole \"pendant\")")
  (action_tile "t11" "(setq hole \"artpack\")")
  (action_tile "t12" "(setq hole \"wifi\")")
  (action_tile "t13" "(setq hole \"wood_tile\")")
  (action_tile "t14" "(setq hole \"speakers\")")
  (action_tile "t15" "(setq hole \"separate\")")
  (action_tile "t16" "(setq hole \"2x4\")")
  (action_tile "t17" "(setq hole \"restroom_finishes\")")
  (action_tile "t18" "(setq hole \"restroom_fixtures\")")
  (action_tile "t19" "(setq hole \"drive-thru\")")
  (action_tile "t20" "(setq hole \"wall_tile\")")
  (action_tile "t21" "(setq hole \"sills\")")
  (action_tile "t22" "(setq hole \"service\")")
  (action_tile "t23" "(setq hole \"signage\")")
  (action_tile "t24" "(setq hole \"vestibule\")")
  (action_tile "t25" "(setq hole \"pre-order\")")
  (action_tile "t26" "(setq hole \"directional\")")
  (action_tile "t27" "(setq hole \"blade\")")
  (action_tile "t28" "(setq hole \"landscape\")")
  (action_tile "t29" "(setq hole \"tag\")")
  (action_tile "t30" "(setq hole \"metal_panels\")")
  (action_tile "t31" "(setq hole \"canopy_pay\")")
  (action_tile "t32" "(setq hole \"paint_sconce\")")
  (action_tile "t33" "(setq hole \"canopy_pick-up\")")
  (action_tile "t34" "(setq hole \"new_sconce\")")
  (action_tile "t35" "(setq hole \"canopy_DT\")")
  (action_tile "t36" "(setq hole \"paint_storefront\")")
  (action_tile "t37" "(setq hole \"clearance_bar\")")
    
  (action_tile						;action tile for cancel button

    "cancel"						;if cencel button is pressed

    "(done_dialog) (setq UserClick nil)"		;close dialog without excuting dialog functions, set flag

   )							;end action tile for Cancel button

  (action_tile						;action tile for OK button

    "accept"						;if OK button is pressed

    "(done_dialog) (setq UserClick T))"			;close dialog and proceed to excute dialog functions, set flag

    )							;end action tile for OK button

  (start_dialog)					;exciute functions in dialog

  (unload_dialog dcl_id)				;unload dialog after excuting functions

  (princ)

  )							;end defun C:Opt_List

(princ)
    

 

0 Likes
Accepted solutions (1)
3,472 Views
17 Replies
Replies (17)
Message 2 of 18

cdmiske
Enthusiast
Enthusiast

Still have not made progress on my issue.

 

I was originally asking about order of operations on accessing an existing table because I am hoping to be able to make changes to multiple tables that have varying information. This may not be the case with using Auotlisp.

 

I am still learning how to program in Autolisp and try applying ideas that typically would be in game development where you have full access to each asset and can call upon each individual asset independently. I do not think that is possible with Lisp to the best of my knowledge. Someone can correct me if I am wrong.

 

So as best as I can tell I will have to select the table first before initiating the dialog and have the checked boxes execute adding in the wingding check special character in the corresponding boxes within the table.

0 Likes
Message 3 of 18

CodeDing
Advisor
Advisor
Accepted solution

@cdmiske ,

 

Sorry in advance that I will not have a lot of time to go into great detail right now.

From what I can tell.. It seems your immediate question pertains on how to get values into the table most effectively..

In short, you can only edit an object once you know its ENAME..

And you can only get its ENAME 2 ways: Programatically, or by user input.

 

User input would be perhaps easiest to program, but may be 'inefficient' by your means since we do not like having to make users select items.. We could code user selection perhaps one of these 2 ways:

.....
(if (and (setq tbl (car (entsel "\nSelect table: ")))
         (eq "ACAD_TABLE" (cdr (assoc 0 (entget tbl)))))
  ;Do stuff after table has been selected
);if
.....
.....
;we could also select many tables
(while (and (setq tbl (car (entsel "\nSelect table: ")))
            (eq "ACAD_TABLE" (cdr (assoc 0 (entget tbl)))))
  ;Do stuff after each table has been selected
);while
.....

Programatically would be most efficient for user, but harder to program..

We need SOME type of identifying material that would help us determine that we have selected the correct table each time, such as the table title, if we can GUARANTEE that it will be this way each time..

We can use our selection set filters to get our table. Something like:

.....
(setq title "My Table Title")
(if (setq ss (ssget "_X" (list '(0 . "ACAD_TABLE") (cons 1 title) (cons 302 title))))
  (progn
    (setq ename (ssname ss 0))
    ;Do stuff with table
  );progn
);if
.....

be careful with that method though because if any other cell in any other table has the value of your title, then it would pick that up too.. You would need to create a more elaborate filter to account for that.

 

You would only call your dialog box in my provided 'Do stuff' areas after we can guarantee to the user that our table has been found / stored.

 

Does this help?

Best,

~DD

Message 4 of 18

cdmiske
Enthusiast
Enthusiast

Thank you. This helps me a lot actually.

 

I have been trying to learn how to grab the asset name or "ENAME" so that I can edit specific cells in different tables. Given that I have a basic programming background using game engines primarily it has presented some issues in transitioning to using Lisp for AutoCAD.

 

Because I am working on nothing but restaurants (new and remodel) the information remains very much the same from store to store because I have a base model for each type of store design. I still do get the complete custom store that was converted from a different type of restaurant though. I have already built a complete library of sections, plans, details, dynamic blocks, etc... along with sheet sets that I can reuse in all my drawings. Now I am taking that a step further by using Lisp to automate much of the layout process for the sheets and views. to minimize all the time it takes to set things up for each store. In some cases I might not have to do any work past running all the setup scripts whereas other times I can focus solely on the differences of the building at a particular site.

0 Likes
Message 5 of 18

CodeDing
Advisor
Advisor

Glad it helped. Don't hesitate coming back to the forums for assistance where you run into any roadblocks.

Message 6 of 18

cdmiske
Enthusiast
Enthusiast

I was reading a programming book for Lisp in AutoCAD R10 and discovered that there is a way to establish global variables that are active while autoCAD is open so it can carry from drawing to drawing during a session. I might try experimenting with this as what I was looking at will be spread over several sheets that use this setup routine I have been building.

0 Likes
Message 7 of 18

Sea-Haven
Mentor
Mentor

A couple of extra ideas if your table has a description in a cell "Table 1" you can find the table. Every object in a dwg has a unique ID known as the Handle this can be useful, there is also xdata where you can save stuff in the dwg like last table name, a simpler method also is the USERI,USERR and USERS1-5 variables.

0 Likes
Message 8 of 18

cdmiske
Enthusiast
Enthusiast

@Sea-Haven 

 

Thank you for the tips. There is a lot to learn and this is my first foray into the deep end of trying to build LISP routines. I have done some dabbling with modifying routines that others have developed. I would say I am in over my head and that is how one learns. I know I have said other times that I am taking more of a game development approach to what I am trying to accomplish. Hopefully it will all pan out to where I can do less work and have more time.

0 Likes
Message 9 of 18

Sea-Haven
Mentor
Mentor

You have a massive dcl but it only returns 1 answer is that correct ?

 

Do you want more answers so can pick multiple choices in one go ? If so use a cons to make a list of hole options.

0 Likes
Message 10 of 18

cdmiske
Enthusiast
Enthusiast

Yes I am hoping to use this as a selection set. So far I have been following tutorials to get that far. I figure i have mistakes in there but would eventually find that out through testing. What I have not done yet is tie each selection to fill out a cell on the table. Those options are the same as what is shown on the table for the title sheet for the scope of the project. I also wanted to tie that into the responsibility matrix to indicate what the General Contractor, Electrical Contractor, and Plumber would be responsible for. Because there are options for finishes and not all items are used for each store being able to make sure that both scope of work and the responsibility matrix match is important. Many times this does not line up resulting in a few thousand dollars in change orders which sucks. I am turning out almost 30 sets a year so making sure I can get information correct is paramount.

 

I have attached both drawing files for reference. The cover sheet and the sheet containing the responsibility matrix.

0 Likes
Message 11 of 18

Sea-Haven
Mentor
Mentor

Have a look over at Cadtutor, Downloads for "Multi toggles.lsp" I wrote it, you can select as many as you want on or off, the thing here is it goes through each toggle and asks is on or off. So end up with a list that looks like this (0 0 1 0 1 1...……. the 1 is on 0 is off the list matches the item in another list in your case your 100+ hole descriptions.

 

The only thing to remember is that the 1st item in a list is zero not 1. Use nth function to compare the two lists. 

 

It can not do as many as you have as its single column but uses lists to make the dcl on the fly so no need for every line in the dcl to be coded. The toggle button id is auto created so you could add or subtract from a list and it will auto write the temporary dcl.

 

I guess the need for a multi boxed dcl on the fly, if you could group your choices then multi toggles may work for you by running multi times but each answer is saved toa different variable and compares correct list.

 

This is code that's all

 (if (not AH:Toggs)(load "Multiple toggles.lsp"))
(setq ans (reverse (ah:toggs   '("A B C D" "A" "B" "C" "D"))))

(setq ans (reverse (ah:toggs   '("Hole choices" "Hole type A" "Hole type B" "Hole diamond" "Hole square"))))

 

 

 

 

Message 12 of 18

cdmiske
Enthusiast
Enthusiast

@Sea-Haven 

 

Thank you for all the help. I had to switch gears for the moment to draw layouts for my clients stores for COVID-19 layouts. I will check out your tutorial and work at implementing what I learn into the function I am trying to make.

0 Likes
Message 13 of 18

Sea-Haven
Mentor
Mentor

Grr or Grrr has some nice dcl functions as well for multiple inputs.

Message 14 of 18

cdmiske
Enthusiast
Enthusiast

@Sea-Haven 

 

You continue to be a wealth of information. I appreciate all the assistance and will research those as well for what I am trying to do. 

0 Likes
Message 15 of 18

Sea-Haven
Mentor
Mentor

Looking at your dwgs should have done that 1st a combo of pick type then a pop up list would make sense www.lee-mac.com has a nice double list dcl left is master list right is the to be added so the second list is what you want.

 

You could set up the multi radio buttons.lsp to select the type, then call lee's.

Message 16 of 18

cdmiske
Enthusiast
Enthusiast

@Sea-Haven 

 

I have been relying heavily on Lee-Mac's site for reference. He has a wealth of information and lots of good tools too. I will have to check out the reference you mentioned. Again thank you!

0 Likes
Message 17 of 18

Sea-Haven
Mentor
Mentor
Message 18 of 18

cdmiske
Enthusiast
Enthusiast

@Sea-Haven 

 

That looks amazing! Thank you for posting that and will dig deeper into it when some of this craziness at work calms down a bit.

0 Likes