How to select multiple text in a dialog box to parse through lisp routine

How to select multiple text in a dialog box to parse through lisp routine

dalennea
Enthusiast Enthusiast
5,097 Views
43 Replies
Message 1 of 44

How to select multiple text in a dialog box to parse through lisp routine

dalennea
Enthusiast
Enthusiast

I hope that someone is able to steer me in the right direction. I have created a dialog box that reads in a list of the layers that did not process through a program that I wrote.  Now I built the DCL and have the list of the layers showing up in that dialog box (i.e. list box in DCL) and want to be able to select those layer names either individually or a set and then have them run a routine that will convert the selected layers to the layer that is identified by means of the "radial button".  I have included a pic to hopefully make it clear as to what I want to accomplish... I need some help in how to accomplish this in lisp... 

 

 

Thanks in advance

0 Likes
5,098 Views
43 Replies
Replies (43)
Message 21 of 44

john.uhden
Mentor
Mentor
Get rid of the 2nd parenthesis after "Delete"

John F. Uhden

0 Likes
Message 22 of 44

dalennea
Enthusiast
Enthusiast

I went ahead and changed the syntax and get "nil" & "T"

 

(action_tile "layerlist" "(setq layers (@layerlist $value))")
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq action (start_dialog))
(cond
((/= action 1)) ;; do nothing
((= choice "delete")
(foreach layer layers (command "-laydel" "n" layer "" "y"))
)
)
)
)

0 Likes
Message 23 of 44

dalennea
Enthusiast
Enthusiast

Question... with the (command "-laydel" "n" layer "" "y").... does it have the ability to delete several layers at one time ?

0 Likes
Message 24 of 44

john.uhden
Mentor
Mentor
That's fine. I just don't trust that T is always T.
But I'm damned sure that 1 is always 1.
I trust that things are moving along for you now.

John F. Uhden

0 Likes
Message 25 of 44

dalennea
Enthusiast
Enthusiast

Well... I must still have syntax wrong... smewhere

 

0 Likes
Message 26 of 44

dalennea
Enthusiast
Enthusiast

Because when I select the "delete" on the dialog it doesn't do anything... 

 

0 Likes
Message 27 of 44

dalennea
Enthusiast
Enthusiast

although when I run this at the command prompt (foreach layer layers (command "-laydel" "n" layer "" "y")) then it will delete the layers... there has to be something wrong with my syntax

0 Likes
Message 28 of 44

john.uhden
Mentor
Mentor
Well, before you injure yourself, you should post what you have. We here
are indemnified from damages suffered by masochistic visitors.

John F. Uhden

0 Likes
Message 29 of 44

dalennea
Enthusiast
Enthusiast

Now that was the best laugh I had all day....

//---------------------------------------------------------------------------------------------------------
// Architectural Layers Conversion Program - List Box Capture
//---------------------------------------------------------------------------------------------------------

(defun @layerlist (str / lst)
(foreach i (read (strcat "(" str ")"))
(setq lst (cons (nth i txtlist) lst))
)
(reverse lst)
)


//---------------------------------------------------------------------------------------------------------
// Architectural Layers Conversion Program - Create Layers
//---------------------------------------------------------------------------------------------------------

(defun c_layers (/)
(command "-layer" "n" "A-COL, A-DOOR, A-FLOR-STRS, A-FURN, A-MOD-PNL, A-MOD-WKSF, A-WALL, A-WIND" "")
)

//---------------------------------------------------------------------------------------------------------
// Architectural Layers Conversion Program - Delete Layers
//---------------------------------------------------------------------------------------------------------

(defun dal ()
(command "-laydel" "n" "layers" "" "y")
)

//---------------------------------------------------------------------------------------------------------
// Architectural Layers Conversion Program - Load text file from creation
//---------------------------------------------------------------------------------------------------------

(defun c:archi ( / result dcl_id)
(setq txtlist (list))
(setq openfile (open "c:/lsp/david.txt" "r")); reading the list
(while (setq line (read-line openfile))
(setq txtlist (append txtlist (list line)))
)
(close openfile)

//---------------------------------------------------------------------------------------------------------
// Architectural Layers Conversion Program - Load DCL Box for list
//---------------------------------------------------------------------------------------------------------

(setq dcl_id (load_dialog "DCR_PROGRAM.dcl")); loading the DCL
(if (not (new_dialog "dcl_test" dcl_id))
(progn
(alert "The DCR PROGRAM.dcl file could not be loaded!")
(exit)
)
)

(progn

(start_list "layerlist")
(mapcar 'add_list txtlist); Adding the text to the layerlist box
(end_list); end list

//---------------------------------------------------------------------------------------------------------
// Architectural Layers Conversion Program - Tile actions for conversion of selected text from list
//---------------------------------------------------------------------------------------------------------


(action_tile "layerlist" "(setq layers (@layerlist $value))")
(action_tile "accept" "(done_dialog 1)")
(action_tile "cancel" "(done_dialog 0)")
(setq action (start_dialog))
(cond
((/= action 1)) ;; do nothing
((= choice "delete")
(foreach layer layers (command "-laydel" "n" layer "" "y"))
)
)

;(action_tile "a-convert" "(done_dialog)(setq result T))")
;(action_tile "a-col" "(done_dialog)(setq result nil))")
;(action_tile "a-door" "(done_dialog)(setq result nil))")
;(action_tile "a-flor-strs" "(done_dialog)(setq result nil))")
;(action_tile "a-furn" "(done_dialog)(setq result nil))")
;(action_tile "a-mod-wksf" "(done_dialog)(setq result nil))")
;(action_tile "a-mod-wall" "(done_dialog)(setq result nil))")
;(action_tile "a-mod-wind" "(done_dialog)(setq result nil))")

;(unload_dialog dcl_id)
;(if result
;(der)
😉
😉
(princ)
😉

 

0 Likes
Message 30 of 44

dalennea
Enthusiast
Enthusiast

there are two right parenthesis missing....

0 Likes
Message 31 of 44

dalennea
Enthusiast
Enthusiast

Here is the DCL... but it has not changed

//---------------------------------------------------------------------------------------------------------
// Architectural Layers Conversion Program - Dialog Box
//---------------------------------------------------------------------------------------------------------
dcl_test : dialog { //dialog name
label = "Architectural Layers Conversion Program - Alpha" ;//give it a label

:boxed_radio_column { //define radio column
label = "Architectural Layers Program" ; //give it a label

: button { //define radion button
key = "a-convert" ; //give it a name
label = "Convert Drawing to Architectural Layers " ; //give it a label
value = "1" ; //switch it on
} //end definition
}
: row {

: boxed_radio_column { //define radio column
label = "Architectural Layers Layers" ; //give it a label
key="RadCol";

: radio_button { //define radio button
key = "a-col" ; //give it a name
label = "A-COL" ; //give it a label
value = "1" ; //switch it on
} //end definition

: radio_button { //define radio button
key = "a-door" ; //give it a name
label = "A-DOOR" ; //give it a label
} //end definition

: radio_button { //define radio button
key = "a-flor-strs" ; //give it a name
label = "A-FLOR-STRS" ; //give it a label
} //end definition

: radio_button { //define radio button
key = "a-furn" ; //give it a name
label = "A-FURN" ; //give it a label
} //end definition

: radio_button { //define radio button
key = "a-mod-pnl" ; //give it a name
label = "A-MOD-PNL" ; //give it a label
} //end definition

: radio_button { //define radion button
key = "a-mod-wksf" ; //give it a name
label = "A-MOD-WKSF" ; //give it a label
}
//end definition
: radio_button { //define radion button
key = "a-mod-wall" ; //give it a name
label = "A-WALL" ; //give it a label
} //end definition
: radio_button { //define radion button
key = "a-mod-wind" ; //give it a name
label = "A-WIND" ; //give it a label
} //end definition
} //end radio column


: boxed_column { //define boxed column
label = "&Layers not converted"; //give it a label

: list_box { //define popup list
key = "layerlist"; //give it a name
height = 10;
width = 55;
multiple_select = true;
fixed_width_font = true;
allow_accept = true; //initial value

} //end list

} //end boxed column

} //end row

: row {
fixed_width = true;
label = "Progress Bar";
key = "br-label";
: row {
: button {
key = "convert";
label = "Convert";
mnemonic = "T";
is_cancel = true;
}
}
: row {
: button {
key = "delete";
label = "Delete Layer";
mnomonic = "E";
is_cancel = true;
}
}

: row {
: button {
key = "accept";
label = "Ok";
mnomonic = "k";
is_cancel = true;
}
}

: row {
: button {
key = "cancel";
label = "Cancel";
mnomonic = "a";
is_cancel = true;
}
}

: image {
key = "progbar";
fixed_width = 300;
height = 3;
}
/// This Tile may also be put below the OK_Cancel buttons

: row {
: errtile {
label = "";
key = "error";
width = 26;
}
}
}


: text_part { //define text
label = "Developed"; //give it some text
} //end text

: text_part { //define more text
label = "by the Phantom"; //some more text
} //end text


} //end dialog

0 Likes
Message 32 of 44

john.uhden
Mentor
Mentor

1.  Well, fortunately you don't use the dal function anywhere, because if you look at it you will see that it will delete only a layer named "layers."

2.  I was thinking that you had  a radio_column of radio_buttons for each action you wanted to take on the list of selected layers, like...

(action_tile "Delete" "(setq choice $key)")

(action_tile "Rename" "(setq choice $key)")

etc.

Then if "accept" were hit, it would conditionally operate based on the choice.

3.  Of course before you forge ahead with accepting an "accept" you should have a function to see if...

(a) any layers were selected.

(b) any choice was selected.

And if not, you put a warning message in the errtile and let the dialog keep running.

BTW, if you really need to grab the user's attention, you can call the alert function while a dialog is open.

Keep it going; you're getting closer.

John F. Uhden

0 Likes
Message 33 of 44

dalennea
Enthusiast
Enthusiast

I don't know how to do err traps

0 Likes
Message 34 of 44

john.uhden
Mentor
Mentor

We're really not talking about error trapping.

Here we're talking about your control of your own program.

I am suggesting <strongly> that rather than...

(action_tile "accept" "(done_dialog 1)")

that instead...

(action_tile "accept" "(check_input)")

where...

(defun check_input ()

  (if (and layers choice)

    (done_dialog 1)

    (set_tile "error" "Please complete your selections.")

  )

)

John F. Uhden

0 Likes
Message 35 of 44

dalennea
Enthusiast
Enthusiast

So how would I keep the dialog box in place while it passes the functions and completes... 

 

0 Likes
Message 36 of 44

john.uhden
Mentor
Mentor
For this little app the only purpose of the dialog is to get input
(choices), so once you have that close the dialog and finish what you have
to do.
There are occasions when you want to keep the dialog open such as for
displaying totals of areas or lengths per layer or something in a list box.

John F. Uhden

0 Likes
Message 37 of 44

dalennea
Enthusiast
Enthusiast

Ok... I can understand that... Question.... is it possible that in the dialog box that I want to rename a layer selected and set it to one of those specified buttons....(i.e. A-FURN) I select a layer from the list and then the button and it changes it to that existing layer.... 

0 Likes
Message 38 of 44

john.uhden
Mentor
Mentor
You could have two (2) list_boxes. The 2nd would be a list of target layer
names (not multiple_select). Of course you can't rename multiple layers to
one, so maybe you actually want to change all entities on layers A, B, and
C to layer D. That's easy.

John F. Uhden

0 Likes
Message 39 of 44

dalennea
Enthusiast
Enthusiast

Thanks for the response... how would I go about then the later of "maybe you actually want to change all entities on layers A, B, and
C to layer D. That's easy"

0 Likes
Message 40 of 44

john.uhden
Mentor
Mentor
Okay, so you have a list of selected layers (which I presume already exist
in the drawing).
And now you have a list_box to pick one (1) target layer.
When the user clicks OK (and check_input is good) you close the dialog and
then...
(foreach layer layers
(and
(setq ss (ssget "X" (list (cons 8 layer))))
(vl-cmdf "_.chprop" ss "" "_LA" target "")
)
)
Alternatively we could write a function to convert a list into a
comma-delimited string...
("A" "B" "C" "D") -> "A,B,C,D"
and run the CHPROP command once, but I'm just trying to have you get the
basics down before losing you with apply mapcar.

John F. Uhden

0 Likes