Jump to content

Retriving main dialog if selection set is nil


Saxlle

Recommended Posts

Hello everyone,

 

I'm the new one in autolisp programming, and i'm trying to link lisp file with dcl file. In my lisp file and dcl file i'm trying to develop an application where after pressing "Execute" button, the main dialog is hidden, then start processing code inside the "Execute" button where prompt to user to select object's in drawing to proceed calculation of lengths of line, polylines, lwpolylines, etc.

 

The main problem i have and don't know how to do that/solve is: when using (setq ss (ssget '((-4 . "<or") (0 . "INSERT,POLYLINE,LWPOLYLINE,LINE,ARC,SPLINE") (-4 . "or>")))), where before that is prompted to user to "Select linear object's for calculating total lengths", and after selecting in model space where the variable "ss" is "nil" (there is no selected object's) the main dialog is returned (with basic setup which are shown in dialog when first time started) instend of "error: bad argument type: lselsetp nil" and abort/exit from dialog. This functionallity will be helpful to prevent everytime abort/exit an app (if there is no selected object's), instend of again calling in AutoCAD command for starting lsp file to load dialog and the rest. Also, i want to tnx to AfraLISP who provide a topic with "Hiding Dialog Boxes" which are really helpful for me (and maybe to update topic or create a new on if there solution for that which i described in)! I will post a lsp and dcl file which i writte using notepad++.

 

*CalculateLengths10 lsp file below.

(prompt "Komanda za pokretanje ==> CALCLENGTH10 <==")

(defun c:CALCLENGTH10 (/ dwgname spec_name def_name def_val_sum def_val flag path dialogshow  dcl_id file_name filecreate author 						  acad_date_time day month year cur_date hour minutes seconds cur_time 
						 true_filename answ name1 name2 name3 name3 name5 spec_sum_name1 spec_sum_name2 spec_sum_name3 			  						   spec_sum_name4 spec_sum_name5 global_width standard_222 standard_223 ss len i 
			 			 sum_name1 sum_name2 sum_name3 sum_name4 sum_name5 ename data layername blockname entity_type 					     			 global_width_entity entity_length wr_line1 wr_line2 wr_line3 wr_line4 wr_line5 
			 			 sum_name1_m2 sum_name2_m2 sum_name3_m2 sum_name4_m2 sum_name5_m2)
	(setvar "cmdecho" 0)
	(setq dwgname (substr (getvar "dwgname") 1 (- (strlen (getvar "dwgname")) 4)))
	(setq spec_name (strcat dwgname "_d=0.10"))
	(setq def_name "Specifikacija" def_val_sum 0.00 def_val 0.10 flag 4 sum_name1 0.00 sum_name1_m2 0.00 sum_name2 0.00 				  sum_name2_m2 0.00 sum_name3 0.00 sum_name3_m2 0.00 sum_name4 0.00 sum_name4_m2 0.00 sum_name5 0.00 sum_name5_m2 0.00)
	(setq 
	 name1 "PP_801_RAZDELNA NEISPREKIDANA LINIJA 0.10 m"
	 name2 "PP_802_RAZDELNA NEISPREKIDANA LINIJA 0.10 m"
	 name3 "PP_803_RAZDELNA NEISPREKIDANA LINIJA ZIG-ZAG 0.10 m"
	 name4 "PP_805_IVICNA NEISPREKIDANA LINIJA 0.10 m"
	 name5 "1-1010"
	 spec_sum_name1 "Duzina razdelne neisprekidane linije bele boje:"
	 spec_sum_name2 "Duzina razdelne neisprekidane linije zute boje:"
	 spec_sum_name3 "Duzina razdelne neisprekidane zig-zag linije bele boje:"
	 spec_sum_name4 "Duzina neisprekidane ivicne linije bele boje:"
	 spec_sum_name5 "Duzina linije vodilje 1+1+1 bele boje:"
	 global_width 0.10
	 standard_222 "Oznake na putu - Uzduzne oznake - Neisprekidane linije (SRPS U.S4.222)"
	 standard_223 "Oznake na putu - Uzduzne oznake - Isprekidane linije (SRPS U.S4.223)"
	 )
	 (setq path (findfile (strcat ".\\" def_name)))
	 (setq dialogshow T)
	 (setq dcl_id (load_dialog "CalculateLengthsAndArea.dcl"))
	 (while (> flag 2)
		 (if (not (new_dialog "CalculateLengths10" dcl_id))
				(setq dialogshow nil)	
		 )		 
	 (action_tile "execute" "(done_dialog flag)")
	 (action_tile "cancle" "(cancle)")
	 (action_tile "about" "(about)")
	 (action_tile "save_file" "(save)")
	 (action_tile "choose_location" "(choose_location)")
	 (set_tile "name1_m" (rtos sum_name1))
	 (set_tile "name1_m2" (rtos sum_name1_m2))
	 (set_tile "name2_m" (rtos sum_name2))
	 (set_tile "name2_m2" (rtos sum_name2_m2))
	 (set_tile "name3_m" (rtos sum_name3))
	 (set_tile "name3_m2" (rtos sum_name3_m2))
	 (set_tile "name4_m" (rtos sum_name4))
	 (set_tile "name4_m2" (rtos sum_name4_m2))
	 (set_tile "name5_m" (rtos sum_name5))
	 (set_tile "name5_m2" (rtos sum_name5_m2))
	 (set_tile "file_name" spec_name)
	 (set_tile "file_save_path" path)
	 (setq flag (start_dialog))
	 ;; prilikom klika na dugme "Execute" u DCL-u poziva se funkcija (execute)
	 (execute)
	)
	(unload_dialog dcl_id)
	(princ)
)

;; Cancle button
(defun cancle ()
	(done_dialog)
	(setq dialogshow nil)
	(prompt "Prestanak izvrsavanja aplikacije...")
	(princ)
)

;;Execute button
(defun execute ()
		(if (= flag 4)
			(progn
				(prompt "Selektujte linijske objekte za proracun ukupne duzine") (princ)
				(terpri)
				(if (= ss nil)
					(progn
						;;(new_dialog "CalculateLengths10" dcl_id)
						(set_tile "error" "Nije pronadjen ni jedan objekat debljine d=0.10 m!")
						;;(start_dialog)
						(princ)
					)
				)
				(setq len (sslength ss))
				(setq i 0)
				(setq sum_name1 0 sum_name2 0 sum_name3 0 sum_name4 0 sum_name5 0)
				(while (< i len)
					(setq ename (ssname ss i))
					(setq data (entget (ssname ss i)))
					(setq layername (cdr (assoc 8 data)))
					(setq blockname (cdr (assoc 2 data)))
					(setq entity_type (cdr (assoc 0 data)))
					(setq global_width_entity (cdr (assoc 40 data)))
					(cond
						((and (= layername name1) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
							(setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
							(setq sum_name1 (+ sum_name1 entity_length))
						)
						((and (= layername name2) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
							(setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
							(setq sum_name2 (+ sum_name2 entity_length))
						)
						((and (= layername name3) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
							(setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
							(setq sum_name3 (+ sum_name3 entity_length))
						)
						((and (= layername name4) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
							(setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
							(setq sum_name4 (+ sum_name4 entity_length))
						)
						((and (= blockname name5) (= entity_type "INSERT"))
							(setq sum_name5 (1+ sum_name5))
						)
					)
					(setq i (1+ i))
					(princ)
				)
				(mode_tile "name1_m" 0)
				(mode_tile "name1_m2" 0)
				(mode_tile "name2_m" 0)
				(mode_tile "name2_m2" 0)
				(mode_tile "name3_m" 0)
				(mode_tile "name3_m2" 0)
				(mode_tile "name4_m" 0)
				(mode_tile "name4_m2" 0)
				(mode_tile "name5_m" 0)
				(mode_tile "name5_m2" 0)
				
				(if (= sum_name1 0)
					(progn
						(setq sum_name1_m2 (* sum_name1 def_val))
						(mode_tile "name1_m" 1)
						(mode_tile "name1_m2" 1)
					)
					(progn
						(setq sum_name1_m2 (* sum_name1 def_val))
						(mode_tile "name1_m" 1)
						(mode_tile "name1_m2" 1)
					)
				)
				(if (= sum_name2` 0)
					(progn
						(setq sum_name2_m2 (* sum_name2 def_val))
						(mode_tile "name2_m" 1)
						(mode_tile "name2_m2" 1)
					)
					(progn
						(setq sum_name2_m2 (* sum_name2 def_val))
						(mode_tile "name2_m" 1)
						(mode_tile "name2_m2" 1)
					)
				)
				(if (= sum_name3 0)
					(progn
						(setq sum_name3_m2 (* sum_name3 def_val))
						(mode_tile "name3_m" 1)
						(mode_tile "name3_m2" 1)
					)
					(progn
						(setq sum_name3_m2 (* sum_name3 def_val))
						(mode_tile "name3_m" 1)
						(mode_tile "name3_m2" 1)
					)
				)
				(if (= sum_name4 0)
					(progn
						(setq sum_name4_m2 (* sum_name4 def_val))
						(mode_tile "name4_m" 1)
						(mode_tile "name4_m2" 1)
					)
					(progn
						(setq sum_name4_m2 (* sum_name4 def_val))
						(mode_tile "name4_m" 1)
						(mode_tile "name4_m2" 1)
					)
				)
				(if (= sum_name5 0)
					(progn
						(setq sum_name5_m2 (* sum_name5 def_val))
						(mode_tile "name5_m" 1)
						(mode_tile "name5_m2" 1)
					)
					(progn
						(setq sum_name5_m2 (* sum_name5 def_val))
						(mode_tile "name5_m" 1)
						(mode_tile "name5_m2" 1)
					)
				)
			)
		)
	)

;; About button
(defun about ()
	(setq dcl_id_about (load_dialog "CalculateLengthsAndArea.dcl"))
	(if (not (new_dialog "AboutDialog" dcl_id_about))
		(exit)
	)
	(action_tile "accept" "(done_dialog)")
	(start_dialog)
	(unload_dialog dcl_id_about)
	(princ)
)

;; Save button
(defun save ()
	(cond
		((and (= (get_tile "name1_m") (rtos def_val_sum)) (= (get_tile "name1_m2") (rtos def_val_sum))
			  (= (get_tile "name2_m") (rtos def_val_sum)) (= (get_tile "name2_m2") (rtos def_val_sum))
			  (= (get_tile "name3_m") (rtos def_val_sum)) (= (get_tile "name3_m2") (rtos def_val_sum))
			  (= (get_tile "name4_m") (rtos def_val_sum)) (= (get_tile "name4_m2") (rtos def_val_sum))
			  (= (get_tile "name5_m") (rtos def_val_sum)) (= (get_tile "name5_m2") (rtos def_val_sum))
			  )
			(set_tile "error" "Neophodno je izvrsiti Execute pre cuvanja fajla!")
		)
		((and (= spec_name (get_tile "file_name")))
			(setq filecreate (open (strcat path ".\\" spec_name ".csv") "w"))
			(setq acad_date_time (rtos (getvar "CDATE") 2 6))
			(setq day (substr acad_date_time 7 2))
			(setq month (substr acad_date_time 5 2))
			(setq year (substr acad_date_time 1 4))
			(setq cur_date (strcat "Datum: " day "/" month "/" year))
			(setq hour (substr acad_date_time 10 2))
			(setq minutes (substr acad_date_time 12 2))
			(setq seconds (substr acad_date_time 14 2))
			(setq cur_time (strcat "Vreme: " hour ":" minutes ":" seconds))
			(setq header (strcat "Uzduzne oznake na putu debljine d=0.10 m" "," "[m]" "," "[m2]"))
			(write-line author filecreate)
			(write-line cur_date filecreate)
			(write-line cur_time filecreate)
			(write-line header filecreate)
			(write-line "================================================================" filecreate)
			(write-line standard_222 filecreate)
			(if (= sum_name1 0)
				(progn
					(setq sum_name1_m2 (* sum_name1 def_val))
					(setq wr_line1 (strcat spec_sum_name1 "," (rtos sum_name1 2 2) "," (rtos sum_name1_m2 2 2)))
					(write-line wr_line1 filecreate)
				)
				(progn
					(setq sum_name1_m2 (* sum_name1 def_val))
					(setq wr_line1 (strcat spec_sum_name1 "," (rtos sum_name1 2 2) "," (rtos sum_name1_m2 2 2)))
					(write-line wr_line1 filecreate)
				)
			)
			(if (= sum_name2 0)
				(progn
					(setq sum_name2_m2 (* sum_name2 def_val))
					(setq wr_line2 (strcat spec_sum_name2 "," (rtos sum_name2 2 2) "," (rtos sum_name2_m2 2 2)))
					(write-line wr_line2 filecreate)
				)
				(progn
					(setq sum_name2_m2 (* sum_name2 def_val))
					(setq wr_line2 (strcat spec_sum_name2 "," (rtos sum_name2 2 2) "," (rtos sum_name2_m2 2 2)))
					(write-line wr_line2 filecreate)
				)
			)
			(if (= sum_name3 0)
				(progn
					(setq sum_name3_m2 (* sum_name3 def_val))
					(setq wr_line3 (strcat spec_sum_name2 "," (rtos sum_name3 2 2) "," (rtos sum_name3_m2 2 2)))
					(write-line wr_line3 filecreate)
				)
				(progn
					(setq sum_name3_m2 (* sum_name3 def_val))
					(setq wr_line3 (strcat spec_sum_name3 "," (rtos sum_name3 2 2) "," (rtos sum_name3_m2 2 2)))
					(write-line wr_line3 filecreate)
				)
			)
			(if (= sum_name4 0)
				(progn
					(setq sum_name4_m2 (* sum_name4 def_val))
					(setq wr_line4 (strcat spec_sum_name4 "," (rtos sum_name4 2 2) "," (rtos sum_name4_m2 2 2)))
					(write-line wr_line4 filecreate)
				)
				(progn
					(setq sum_name4_m2 (* sum_name4 def_val))
					(setq wr_line4 (strcat spec_sum_name4 "," (rtos sum_name4 2 2) "," (rtos sum_name4_m2 2 2)))
					(write-line wr_line4 filecreate)
				)
			)
			(write-line "================================================================" filecreate)
			(write-line standard_223 filecreate)
			(if (= sum_name5 0)
				(progn
					(setq sum_name5_m2 (* sum_name5 def_val))
					(setq wr_line5 (strcat spec_sum_name5 "," (rtos sum_name5 2 2) "," (rtos sum_name5_m2 2 2)))
					(write-line wr_line5 filecreate)
				)
				(progn
					(setq sum_name5_m2 (* sum_name5 def_val))
					(setq wr_line5 (strcat spec_sum_name5 "," (rtos sum_name5 2 2) "," (rtos sum_name5_m2 2 2)))
					(write-line wr_line5 filecreate)
				)
			)
			(close filecreate)
			(set_tile "error" "-------------> Fajl je uspesno sacuvan! <-------------")
		)
		((/= true_filename spec_name)
			(setq filecreate (open file_name "w"))
			(setq acad_date_time (rtos (getvar "CDATE") 2 6))
			(setq day (substr acad_date_time 7 2))
			(setq month (substr acad_date_time 5 2))
			(setq year (substr acad_date_time 1 4))
			(setq cur_date (strcat "Datum: " day "/" month "/" year))
			(setq hour (substr acad_date_time 10 2))
			(setq minutes (substr acad_date_time 12 2))
			(setq seconds (substr acad_date_time 14 2))
			(setq cur_time (strcat "Vreme: " hour ":" minutes ":" seconds))
			(setq header (strcat "Uzduzne oznake na putu debljine d=0.10 m" "," "[m]" "," "[m2]"))
			(write-line author filecreate)
			(write-line cur_date filecreate)
			(write-line cur_time filecreate)
			(write-line header filecreate)
			(write-line "================================================================" filecreate)
			(write-line standard_222 filecreate)
			(if (= sum_name1 0)
				(progn
					(setq sum_name1_m2 (* sum_name1 def_val))
					(setq wr_line1 (strcat spec_sum_name1 "," (rtos sum_name1 2 2) "," (rtos sum_name1_m2 2 2)))
					(write-line wr_line1 filecreate)
				)
				(progn
					(setq sum_name1_m2 (* sum_name1 def_val))
					(setq wr_line1 (strcat spec_sum_name1 "," (rtos sum_name1 2 2) "," (rtos sum_name1_m2 2 2)))
					(write-line wr_line1 filecreate)
				)
			)
			(if (= sum_name2 0)
				(progn
					(setq sum_name2_m2 (* sum_name2 def_val))
					(setq wr_line2 (strcat spec_sum_name2 "," (rtos sum_name2 2 2) "," (rtos sum_name2_m2 2 2)))
					(write-line wr_line2 filecreate)
				)
				(progn
					(setq sum_name2_m2 (* sum_name2 def_val))
					(setq wr_line2 (strcat spec_sum_name2 "," (rtos sum_name2 2 2) "," (rtos sum_name2_m2 2 2)))
					(write-line wr_line2 filecreate)
				)
			)
			(if (= sum_name3 0)
				(progn
					(setq sum_name3_m2 (* sum_name3 def_val))
					(setq wr_line3 (strcat spec_sum_name2 "," (rtos sum_name3 2 2) "," (rtos sum_name3_m2 2 2)))
					(write-line wr_line3 filecreate)
				)
				(progn
					(setq sum_name3_m2 (* sum_name3 def_val))
					(setq wr_line3 (strcat spec_sum_name3 "," (rtos sum_name3 2 2) "," (rtos sum_name3_m2 2 2)))
					(write-line wr_line3 filecreate)
				)
			)
			(if (= sum_name4 0)
				(progn
					(setq sum_name4_m2 (* sum_name4 def_val))
					(setq wr_line4 (strcat spec_sum_name4 "," (rtos sum_name4 2 2) "," (rtos sum_name4_m2 2 2)))
					(write-line wr_line4 filecreate)
				)
				(progn
					(setq sum_name4_m2 (* sum_name4 def_val))
					(setq wr_line4 (strcat spec_sum_name4 "," (rtos sum_name4 2 2) "," (rtos sum_name4_m2 2 2)))
					(write-line wr_line4 filecreate)
				)
			)
			(write-line "================================================================" filecreate)
			(write-line standard_223 filecreate)
			(if (= sum_name5 0)
				(progn
					(setq sum_name5_m2 (* sum_name5 def_val))
					(setq wr_line5 (strcat spec_sum_name5 "," (rtos sum_name5 2 2) "," (rtos sum_name5_m2 2 2)))
					(write-line wr_line5 filecreate)
				)
				(progn
					(setq sum_name5_m2 (* sum_name5 def_val))
					(setq wr_line5 (strcat spec_sum_name5 "," (rtos sum_name5 2 2) "," (rtos sum_name5_m2 2 2)))
					(write-line wr_line5 filecreate)
				)
			)
			(close filecreate)
			(set_tile "error" "-------------> Fajl je uspesno sacuvan! <-------------")
		)
	)
)

;; Choose location button
(defun choose_location ()
	(setq file_name (getfiled "Snimanje specifikacije" spec_name "csv" 1))
	(set_tile "file_save_path" file_name)
	(setq true_filename (vl-filename-base file_name))
	(set_tile "file_name" true_filename)
)

DCL file below

CalculateLengths10

:dialog {
	
	label = "CalculateLengths10";

	:row {
		:boxed_column {
			
			label = "Uzduzne oznake na putu debljine d=0.10 m";
				:row {
					:spacer {width = 43;}
					:text {label = "[m]          [m2]";}
				 }
				 :row {
					:text {label = "Duzina razdelne neisprekidane linije bele boje:";}
				 	:edit_box {key = "name1_m"; width = 12.1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 	:edit_box {key = "name1_m2"; width = 1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 }
				 :row {
					:text {label = "Duzina razdelne neisprekidane linije zute boje:";}
				 	:edit_box {key = "name2_m"; width = 12; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 	:edit_box {key = "name2_m2"; width = 1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 }
				 :row {
					:text {label = "Duzina razdelne neisprekidane zig-zag linije bele boje:";}
				 	:edit_box {key = "name3_m"; width = 1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 	:edit_box {key = "name3_m2"; width = 1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 }
				 :row {
					:text {label = "Duzina neisprekidane ivicne linije bele boje:";}
				 	:edit_box {key = "name4_m"; width = 14.5; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 	:edit_box {key = "name4_m2"; width = 1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 }
				 :row {
					:text {label = "Duzina linije vodilje 1+1+1 bele boje:";}
				 	:edit_box {key = "name5_m"; width = 20.1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 	:edit_box {key = "name5_m2"; width = 1; edit_width = 4; edit_limit = 5; is_enabled = false;}
				 }
				 :spacer {width = 5;}
				 :row {
					//:button {label = "OK"; key = "accept"; mnemonic = "O"; alignment = centered; fixed_width = true;}
					//:spacer {width = 7;}
					:button {label = "Execute"; key = "execute"; mnemonic = "E"; alignment = centered; fixed_width = true; is_default = true;}
					:spacer {width = 7;}
					:button {label = "Cancle"; key = "cancle"; mnemonic = "C"; alignment = centered; fixed_width = true; is_cancel=true;}
				 }
		}

		:boxed_column {
			label = "Save File";
				:column {
					:spacer {height = 1;}
					:edit_box {label = "File name:"; key = "file_name"; edit_width = 60; edit_limit = 100;}
					:edit_box {label = "File save path:"; key = "file_save_path"; edit_width = 60; edit_limit = 100;}
					:row {
						:spacer {width = 1;}
						:button {label = "Choose another file location..."; key = "choose_location"; mnemonic = "C"; fixed_width = true;}
					     }
				}
				:spacer {height = 3.5;}
				:row {
					:button {label = "Save File"; key = "save_file"; mnemonic = "S"; alignment = centered; fixed_width = true;}
					:errtile {alignment = centered; width = 37;}
					:button {label = "About..."; key = "about"; mnemonic = "A"; fixed_width = true;}
				}
		}
	}
}

AboutDialog

:dialog {
	label = "Contact info";
	:paragraph {
		:text_part {
			label = "Aplikacija je namenjena za proracun ukupne duzine";
			alignment = centered;
		}
		:text_part {
			label = "uzduznih oznaka na putu!";
			alignment = centered;
		}
		:spacer {height = 1;}
		:text_part {
			label = "Email: aleksandar.subota@outlook.com";
			alignment = centered;
		}
	}
    ok_only;
}

Thank you to everyone who takes the time to read this text and help solve the problem.

main dialog.JPG

Link to comment
Share on other sites

14 hours ago, Saxlle said:

after pressing "Execute" button, the main dialog is hidden, then start processing code inside the "Execute" button where prompt to user to select object's in drawing to proceed calculation of lengths of line, polylines, lwpolylines, etc.

 

That's pretty impressive for just starting Tho I assume you had some help from ChatGPT with how some of those variables are named.

 

The problem looks like the lisp is only checking the variable SS and with a dialog box i guess you would have to close and open it again to allow the user to make a selection. this code would loop until a selection set ss is set. down side is you would either have to make a selection or hit esc to exit loop.

 

;;Execute button
(defun execute ()
  (if (= flag 4)
    (progn
      (prompt "\nSelektujte linijske objekte za proracun ukupne duzine") ;adding "/n" in string is telling autocad to start newline
      (if ss
        (load_dialog dcl_id) ;do nothing
        (progn
          (unload_dialog dcl_id)
          (prompt "\nNišta nije odabrano pokušaj ponovno")           
          (setq ss (ssget '((0 . "INSERT,*POLYLINE,LINE,ARC,SPLINE"))))  
          (execute) to test SS again
        )        
      )
      ....

 

I would suggest having another button next to Execute like "Make Selection" or something. That way you can modify the selection without having to exiting the lisp and starting over.

 

Also these are the same.

(setq ss (ssget '((-4 . "<or") (0 . "INSERT,POLYLINE,LWPOLYLINE,LINE,ARC,SPLINE") (-4 . "or>"))))
(setq ss (ssget '((0 . "INSERT,*POLYLINE,LINE,ARC,SPLINE"))))

 

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

5 hours ago, mhupp said:

That's pretty impressive for just starting Tho I assume you had some help from ChatGPT with how some of those variables are named.

 

The problem looks like the lisp Doesn't have anything adding entities to selection set ss. its only testing if SS is set or not at line 70.

 

http://www.lee-mac.com/ssget.html

(if (= ss nil)
Should be something like
(if (ssget '((0 . "INSERT,LWPOLYLINE"))))

 

Or leave it like that and make another button next to Execute that says Selection. when clicking on that button calls for the selection lisp that allows the user to make the selections. then reopens the dialog box.

 

 

 

 

 

Edited by Saxlle
Link to comment
Share on other sites

5 hours ago, mhupp said:

 

That's pretty impressive for just starting Tho I assume you had some help from ChatGPT with how some of those variables are named.

 

The problem looks like the lisp is only checking the variable SS and with a dialog box i guess you would have to close and open it again to allow the user to make a selection. this code would loop until a selection set ss is set. down side is you would either have to make a selection or hit esc to exit loop.

 

;;Execute button
(defun execute ()
  (if (= flag 4)
    (progn
      (prompt "\nSelektujte linijske objekte za proracun ukupne duzine") ;adding "/n" in string is telling autocad to start newline
      (if ss
        (progn) ;if ss isnt nil do nothing
        (progn
          (unload_dialog dcl_id)
          (prompt "\nNišta nije odabrano pokušaj ponovno")           
          (setq ss (ssget '((0 . "INSERT,*POLYLINE,LINE,ARC,SPLINE"))))  
          (execute) to test SS again
        )        
      )
      ....
  (load_dialog dcl_id)
)

 

I would suggest having another button next to Execute like "Make Selection" or something. That way you can modify the selection without having to exiting the lisp and starting over.

 

Also these are the same.

(setq ss (ssget '((-4 . "<or") (0 . "INSERT,POLYLINE,LWPOLYLINE,LINE,ARC,SPLINE") (-4 . "or>"))))
(setq ss (ssget '((0 . "INSERT,*POLYLINE,LINE,ARC,SPLINE"))))

 

5 hours ago, mhupp said:

 

That's pretty impressive for just starting Tho I assume you had some help from ChatGPT with how some of those variables are named.

 

The problem looks like the lisp is only checking the variable SS and with a dialog box i guess you would have to close and open it again to allow the user to make a selection. this code would loop until a selection set ss is set. down side is you would either have to make a selection or hit esc to exit loop.

 

;;Execute button
(defun execute ()
  (if (= flag 4)
    (progn
      (prompt "\nSelektujte linijske objekte za proracun ukupne duzine") ;adding "/n" in string is telling autocad to start newline
      (if ss
        (progn) ;if ss isnt nil do nothing
        (progn
          (unload_dialog dcl_id)
          (prompt "\nNišta nije odabrano pokušaj ponovno")           
          (setq ss (ssget '((0 . "INSERT,*POLYLINE,LINE,ARC,SPLINE"))))  
          (execute) to test SS again
        )        
      )
      ....
  (load_dialog dcl_id)
)

 

I would suggest having another button next to Execute like "Make Selection" or something. That way you can modify the selection without having to exiting the lisp and starting over.

 

Also these are the same.

(setq ss (ssget '((-4 . "<or") (0 . "INSERT,POLYLINE,LWPOLYLINE,LINE,ARC,SPLINE") (-4 . "or>"))))
(setq ss (ssget '((0 . "INSERT,*POLYLINE,LINE,ARC,SPLINE"))))

 

Thank you mhupp on nice words (I appreciate it). Well, i'm using ChatGPT to help me in searching for the solutions, because sometimes searching for solution on google, forums, ect. can be painfull (it takes a lot of time to find it). Sometimes in ChatGPT on the posted question i get solution, sometimes don't, like for this topic which i post it. The whole logic, def val, especially naming of variables, comments, ect. is mine, and it helps me to easy manipulate in writing the code, finding in code, changing and much more (i love everything to be organized, i'm stubborn as mule 😅).

 

Somehow, when i post the lisp code, it didn't paste (or i miss it in selecting) the part after "prompt" and before (if (== ss nil)...) whic is: (setq ss (ssget '((-4 . "<or") (0 . "INSERT,POLYLINE,LWPOLYLINE,LINE,ARC,SPLINE") (-4 . "or>")))). 

 

The Selection button will be works like Execute button (like now), when it pressed, first prompt user to select objects, then calculate length for the layers who have a predefined names (from 1 to 5), and then retrieve the length in [m] and [m2] in the main dialog (when i test it, it works perfectly). The only thing i want is to prevent exit/aborting from selection set if there is not an objects in layers who have predefined names (from 1 to 5), like nil.

 

Once again, thank you! 😀 I will try with 

Link to comment
Share on other sites

Just a quick look at the code, if ss nil is a problem then add to the IF another progn for SS is not nil this is the way I do it even in big code.

 

(if (= ss nil)
					(progn
						;;(new_dialog "CalculateLengths10" dcl_id)
						(set_tile "error" "Nije pronadjen ni jedan objekat debljine d=0.10 m!")
						;;(start_dialog)
						(princ)
					)
					(progn 
					
					lots of code dcl lengths etc

					) ; end of big code progn
) ; end of if ss nil
) ; maybe end of defun execute

 

  • Like 1
Link to comment
Share on other sites

10 hours ago, BIGAL said:

Just a quick look at the code, if ss nil is a problem then add to the IF another progn for SS is not nil this is the way I do it even in big code.

 

(if (= ss nil)
					(progn
						;;(new_dialog "CalculateLengths10" dcl_id)
						(set_tile "error" "Nije pronadjen ni jedan objekat debljine d=0.10 m!")
						;;(start_dialog)
						(princ)
					)
					(progn 
					
					lots of code dcl lengths etc

					) ; end of big code progn
) ; end of if ss nil
) ; maybe end of defun execute

 

It works, thank you mhupp and BIGAL for responding and help me in finding solution! I do the little update of execute button, and it looks:

 

(defun execute ()
        (if (= flag 4)
            (progn
                (prompt "Selektujte linijske objekte za proracun ukupne duzine") (princ)
                (terpri)
                (setq ss (ssget '((-4 . "<or") (0 . "INSERT,POLYLINE,LWPOLYLINE,LINE,ARC,SPLINE") (-4 . "or>"))))
                (if (= ss nil)
                    (progn
                        (new_dialog "CalculateLengths10" dcl_id)
                        (set_tile "error" "Nije pronadjen ni jedan objekat debljine d=0.10 m! Pokusaj ponovo...")
                        (start_dialog)
                        (done_dialog 0)
                        (princ)
                    )
                    (progn
                        (setq len (sslength ss))
                        (setq i 0)
                        (setq sum_name1 0 sum_name2 0 sum_name3 0 sum_name4 0 sum_name5 0)
                        (while (< i len)
                            (setq ename (ssname ss i))
                            (setq data (entget (ssname ss i)))
                            (setq layername (cdr (assoc 8 data)))
                            (setq blockname (cdr (assoc 2 data)))
                            (setq entity_type (cdr (assoc 0 data)))
                            (setq global_width_entity (cdr (assoc 40 data)))
                            (cond
                                ((and (= layername name1) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
                                    (setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
                                    (setq sum_name1 (+ sum_name1 entity_length))
                                )
                                ((and (= layername name2) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
                                    (setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
                                    (setq sum_name2 (+ sum_name2 entity_length))
                                )
                                ((and (= layername name3) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
                                    (setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
                                    (setq sum_name3 (+ sum_name3 entity_length))
                                )
                                ((and (= layername name4) (= entity_type "LWPOLYLINE") (= global_width global_width_entity))
                                    (setq entity_length (vlax-curve-getDistAtParam ename (vlax-curve-getEndParam ename)))
                                    (setq sum_name4 (+ sum_name4 entity_length))
                                )
                                ((and (= blockname name5) (= entity_type "INSERT"))
                                    (setq sum_name5 (1+ sum_name5))
                                )
                            )
                            (setq i (1+ i))
                            (princ)
                        )
                        (mode_tile "name1_m" 0)
                        (mode_tile "name1_m2" 0)
                        (mode_tile "name2_m" 0)
                        (mode_tile "name2_m2" 0)
                        (mode_tile "name3_m" 0)
                        (mode_tile "name3_m2" 0)
                        (mode_tile "name4_m" 0)
                        (mode_tile "name4_m2" 0)
                        (mode_tile "name5_m" 0)
                        (mode_tile "name5_m2" 0)
                        
                        (if (= sum_name1 0)
                            (progn
                                (setq sum_name1_m2 (* sum_name1 def_val))
                                (mode_tile "name1_m" 1)
                                (mode_tile "name1_m2" 1)
                            )
                            (progn
                                (setq sum_name1_m2 (* sum_name1 def_val))
                                (mode_tile "name1_m" 1)
                                (mode_tile "name1_m2" 1)
                            )
                        )
                        (if (= sum_name2` 0)
                            (progn
                                (setq sum_name2_m2 (* sum_name2 def_val))
                                (mode_tile "name2_m" 1)
                                (mode_tile "name2_m2" 1)
                            )
                            (progn
                                (setq sum_name2_m2 (* sum_name2 def_val))
                                (mode_tile "name2_m" 1)
                                (mode_tile "name2_m2" 1)
                            )
                        )
                        (if (= sum_name3 0)
                            (progn
                                (setq sum_name3_m2 (* sum_name3 def_val))
                                (mode_tile "name3_m" 1)
                                (mode_tile "name3_m2" 1)
                            )
                            (progn
                                (setq sum_name3_m2 (* sum_name3 def_val))
                                (mode_tile "name3_m" 1)
                                (mode_tile "name3_m2" 1)
                            )
                        )
                        (if (= sum_name4 0)
                            (progn
                                (setq sum_name4_m2 (* sum_name4 def_val))
                                (mode_tile "name4_m" 1)
                                (mode_tile "name4_m2" 1)
                            )
                            (progn
                                (setq sum_name4_m2 (* sum_name4 def_val))
                                (mode_tile "name4_m" 1)
                                (mode_tile "name4_m2" 1)
                            )
                        )
                        (if (= sum_name5 0)
                            (progn
                                (setq sum_name5_m2 (* sum_name5 def_val))
                                (mode_tile "name5_m" 1)
                                (mode_tile "name5_m2" 1)
                            )
                            (progn
                                (setq sum_name5_m2 (* sum_name5 def_val))
                                (mode_tile "name5_m" 1)
                                (mode_tile "name5_m2" 1)
                            )
                        )
                    )
                )
            )
        )
    )

Best regards! 👍

Edited by SLW210
Added Code Tags! <>
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...