乐筑天下

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

[编程交流] Expanding a List - Trouble wit

[复制链接]

4

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-5 23:13:15 | 显示全部楼层 |阅读模式
Part of my automation project needs to work off of a list of blocks in a certain format (name l w x y A), I would like to build this from an existing list that has the block names.  My current progress is the following:
 
  1. (defun builditemlist (l /)(princ "\nStartingBuild")         (if (/= l nil)        (progn                                ;if l isnt empty                  ;Take first item in l                (setq item (ssname l 0))                        (princ " GotItem")                ;grab data from INSERT reference (x and y insertion)                  (setq                          ins_block (cdr (assoc 10 (entget item)))                  )                          (princ ins_block)                          (princ "\n")                  ;grab data from BLOCK reference (l and w)                  ;make a list of the form (ssname x y l w A)                (setq                        sublist (list item ins_block)                  )        )                  (progn                                ;if l is empty                (princ "\nDONE!")          )  )         (list sublist (builditemlist (cdr l))))
 
The function is called in the main by:
  1. (setq        tobeshelved (builditemlist tobeshelved)  )
 
 
When I run in AutoCAD, the lists are formed, and do print.  It looks like the error pops up when the tailcall? (not sure im using the correct words) is performed.  
 
The call here:
  1. (list sublist (builditemlist (cdr l)))
 
Is where I think the problem is.  I want the routine to return a list that has its first element as the sublist, then the tail is filled with a call to builditemlist, with just the tail of the original list that was passed to it.
 
The error I get on running this is:
 
StartingBuild GotItem(6.1 72.0 0.0)
; error: bad function: ( (6.1 72.0 0.0))
 
 
Thank you in advance!
回复

使用道具 举报

5

主题

1334

帖子

1410

银币

限制会员

铜币
-20
发表于 2022-7-5 23:34:30 | 显示全部楼层
Maybe this... I've only moved your last line into (if -> then statement); else statement is unnecessary...
 
  1. (defun builditemlist ( l / item ins_block sublist ) (if l   (progn                              ;if l isnt empty                                       ;Take first item in l     (setq item (car l))                                       ;grab data from INSERT reference (x and y insertion)     (setq       ins_block (cdr (assoc 10 (entget item)))     )                                       ;grab data from BLOCK reference (l and w)                                       ;make a list of the form (ssname x y l w A)     (setq       sublist (list item ins_block)     )     (cons sublist (builditemlist (cdr l)))   ) ))
 
The main function should have call to obtain sel. set "ss" and (builditemlist) function should operate on list of entity names obtained from sel. set "ss"...
 
  1. (setq ss (ssget '((0 . "INSERT"))))(setq tobeshelved (builditemlist (vl-remove-if 'listp (mapcar 'cadr (ssnamex ss)))))
回复

使用道具 举报

4

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 00:07:15 | 显示全部楼层
 
Thanks for the suggestions.  In my main I use a nice routine I found here to obtain a SS of the INSERT instances.  That SS is passed to the routine in the setq I wrote out.  I have tried moving the call into the if-then structure, and I get the same 'error; bad function' message
回复

使用道具 举报

4

主题

7

帖子

3

银币

初来乍到

Rank: 1

铜币
20
发表于 2022-7-6 00:29:27 | 显示全部楼层
Ahh!  Nevermind!  Just saw what you were getting at with what I was passing to the sub!  Thanks so much, working great now!
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-11 00:10 , Processed in 0.389213 second(s), 60 queries .

© 2020-2025 乐筑天下

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