Grrr 发表于 2022-7-5 17:51:28

Dynamic block - analyzing (LM&

Hi code fellas,
Today I tried to utilize Lee Mac's "Dynamic Block Functions", and his "List Box".
 
So my attempt is to:
Select a dynamic block and it should return its:
1.Effective name
2.Visibility state parameter's name and its value (maybe a list is better?)
3.List of attribute's names and values (in a listbox)
4.List of parameter's names and values (in a listbox)
 
Ofcourse the reason I'm making a thread is because I probably did something wrong:

(defun C:test ( / sel blkname ) (vl-load-com) (setvar 'errno 0) (prompt "\nSelect block to analyze" ) (if (and (setq sel (ssget "_:S:E" '((0 . "INSERT"))))          (setq blkname (LM:al-effectivename (ssname sel 0)))                        ;

Tharwat 发表于 2022-7-5 17:58:28

Hi,
 
Read the comments of each function and compare it to the error message then you should know how to correct it. (hint : convert it)

Grrr 发表于 2022-7-5 18:05:03

Thanks for the hint, Tharwat!

   (if   (setq vis-state-val (LM:getvisibilitystate (vlax-ename->vla-object (ssname sel 0)) ))   (princ (strcat "\nVisibility state value: " vis-state-val " "))    );if
 
 
I'm almost there!
Do you have any more hints up on your sleeve, about this:

   (if   (setq lst-atts (LM:GetAttributes (ssname sel 0)))   (LM:listbox "Select an attribute" lst-atts 1)    );if
The list box flashes(opens and closes immediately) and I get this:

Select objects:BlockName is "VLD_ОСИ_V3"Visibility state parameter: Visibility1Visibility state value: BothVisibleError: bad argument type: stringp ("X1" . "Ж")
 
I know that the problem is because LM:GetAttributes returns an association list, but how do I split the tags and the values from it? So I end up with two lists for the listbox

Tharwat 发表于 2022-7-5 18:09:17

 
You can use mapcar function to get each tag name and text string in a separate list.
e.g;
 

(mapcar 'car lst-atts) ;;

Grrr 发表于 2022-7-5 18:18:45

Thanks alot, Tharwat!
I often read about mapcar and lambda but they're hard to understand and I rarely use them.
Maybe I'll neeed to learn more about list manipulation, since I'm used to work only with setting quotes in LISP.
 
I have one last question:
 
If I have this list (lst1) , and I filter-out all of its items, except one in a new list (lst2),
and I end up with list which contains only one item - Is it possible to set a quote for that item?
 
Because my current method for handling this problem is this:

    (foreach itm lst ;; For every 'itm' in the list given by 'lst'   (princ (strcat "\nCurrent item is \"" itm "\" "))    ) ;; end foreach
But this seems very limited, as I can't proceed with any IF/COND outside the FOREACH function.

Tharwat 发表于 2022-7-5 18:20:08

You are welcome.
 
 
That is essential and Lisp word is somehow has the combination meaning of the tow words LISt Processing.
 
 
I am sorry I did not get your point.
Why you are after quoting an item from a list since it would be a list at the end ?

Grrr 发表于 2022-7-5 18:26:20

Yes, I've read why its called LISP ! And I'm ashamed with my lack of knowledge using lists !
 
To my question:
I mean if I'm about to extract per one item from 3-4 different lists, wouldn't be more comfortable to quote these items and then proceed?
Otherwise it would become some wrapping of foreach functions, for one element per list:

(foreach itm1 lst1 (foreach itm2 lst2   (foreach itm3 lst3   (do my stuff with itm1 itm2 and itm3)   ) ))
 
Maybe "last" function would help, but I'm not sure:

(setq itm1 (last lst1) )(setq itm2 (last lst2) )(setq itm3 (last lst3) )(do my stuff with itm1 itm2 and itm3)
My question is because that with every code I try to write:
I'm used first to READ/INPUT information (from user) and then the program proceeds and in the end user gets the RETURN information from the program.
 
I try to avoid those syntaxes from the begining to the end of the program, since its very confusing.

Tharwat 发表于 2022-7-5 18:31:41

You need to give a practical example , anyway maybe append function would help to reduce the quantity of foreach function by appending lists into one list then proceed with one list.
 
In regard to quote , I am still can't get your point but anyway there is a function call quote , try it.

Grrr 发表于 2022-7-5 18:37:19

Thank you, Tharwat !
I'm glad that in this forum there are guys like you, skilled and helpful!
I'll continue with my experiments now.

Tharwat 发表于 2022-7-5 18:41:11

I am glad to be of any assistant.
 
Best of luck.
页: [1] 2
查看完整版本: Dynamic block - analyzing (LM&