乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
楼主: Grrr

[编程交流] Dynamic block - analyzing (LM&

[复制链接]

28

主题

317

帖子

292

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
140
发表于 2022-7-5 18:47:46 | 显示全部楼层
Hi Grrrr..
 
2 little comments
 
  1. (cond ((not blkname)          (progn (princ "\nMissed.. Try again!")[color="red"](C:test)[/color])         )         ((not found)          (princ "\n Block not found in drawing !!!")         )         (t...
Having the cond relaunch the c:test command doesnt just relaunch the command, but relaunch it recursively! (hint 1: use a while... hint 2:Maybe you should read that thread made by a nice op called Grrrr who had the same approach before being suggested otherwise with a while example in the best reply he ever received...
 
 
Ah! I just understood the question... set a quote => set quote => (set(quote => setq.
Well, a for-each approach can be used for a list no matters the # of contained arguments. While (last ) retrieve the last element, you could also use (car ) to retrieve the 1rst element, or again the (nth  ) to retrieve a specific element of the list (keeping in mind that the first element of a list is (nth 0 ).  You could use (length ) to verify how many elements are contained in the list and act accordingly only if the length is 1.
 
..as for the quote function, won't be much use for you here. It just instructs cad to returns the expression without evaluating it, so (quote(princ "hello")) would literally return (PRINC "hello")
 
-------
The next part might be usefull to understand return values only if I correctly understood what you meant.
Are you reffering to the returned value of your function? If so, in your example, your users do not get the returned value. The returned value is the last expression evaluated, and the last thing you do is (princ), which exit quietly. Let's take these 2 functions.
  1. (defun foo ()(princ 2)(princ))(defun baz ()2)
By using them, here's what we get.
Even if it looks the same, let's bind their returned value to a symbol and see what happens
zzz doeesn't seems to contain anything, yet is doesn't return nil. If we check what is the type...
now lets check if zzz and (princ) are bound to the same object with the "nasty" (eq function
  1. (eq zzz (princ))T
..so, any program ending by (princ) returns... (princ)
 
Cheers
(princ)
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

Rank: 20Rank: 20Rank: 20Rank: 20

铜币
325
发表于 2022-7-5 18:56:06 | 显示全部楼层
Thanks, Jef!!
 
Excuse me for the recursive relaunch, I grabbed some old routine that I mixed-up and started these experiments.
I hope this would do the job:
  1.     (cond          ((= 52 (getvar 'errno))          (princ "\nMissed.. Try again!")(C:test)         )         ((null sel)          (princ "\nYou missed, try again.")(C:test)         )         ((not blkname)          (princ "\n Missed name of block ***")         )         ((not found)          (princ "\n Block not found in drawing !!!")         )         (t          (princ "\n couldn't find any block !!! ")         )   );cond
 
Before your post I figured out that I might just use (setq setquoteditem (car listwithoneitem))
such method didn't feel very right to me so I had to ask, but reading this from your post:
by providing the length check for the list first would make the code look more right
 
 
 
Anyway, everything seems to work fine..
I get all the attribute tags in the listbox
I get all the attribute values in the listbox
I get all the parameter tags in the listbox
But I do not get the parameter values in the listbox
 
So the reason why (it might be) is because that the "lst-param-vals" must contain a mix of numbers/strings/symbols.
With my lack of list experience I came up with this (my concept doesn't work ofcourse):
  1. (setq lst-param-vals (append '(mapcar 'cdr lst-params) lst-param-vals)) ; create list with 2nd associated element from lst-params; sort the items from the "lst-param-vals", by constructing sorted lists(foreach itm lst-param-vals(cond ((numberp itm) (setq listwithnumbers '()) (append itm listwithnumbers) ; add it to numbers list ) ((stringp itm) (setq listwithstrings '()) (append itm listwithstrings) ; add it to strings list ) ((symbolp itm) (setq listwithsymbols '()) (append itm listwithsymbols) ; add it to symbols list ));cond);end of foreach (print listwithnumbers) (print listwithstrings) (print listwithsymbols)
Construct lists to sort out the different items.
 
 
 
 
However I'm not sure I'm going on the right track, I mean:
  1. ;; Get Dynamic Block Properties  -  Lee Mac;; Returns an association list of Dynamic Block properties & values.;; blk - [vla] VLA Dynamic Block Reference object;; Returns: [lst] Association list of (( . ) ... )
How does one who gets such association list could benefit from it?
 
The way I could think of it is to extract the  and the  of one or a few items and for example put some conditioning to select by/match by these attribute's/parameter's tags/values.
 
(maybe for this question I should start new thread, because it could be long to discuss - working with assoc lists)
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-13 00:44 , Processed in 0.358900 second(s), 54 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表