乐筑天下

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

[编程交流] Sequential Layer naming + Lisp

[复制链接]

5

主题

8

帖子

3

银币

初来乍到

Rank: 1

铜币
25
发表于 2022-7-5 16:47:25 | 显示全部楼层 |阅读模式
Hi All
 
Firstly, many thanks to everyone who contributes to this site, it is an immensely helpful source of info.
 
I have been using AutoCAD for many years and have recently started to play around with AutoLISP to try and streamline some repetitive commands, I can generally construct simple routines but have bitten off more than I can chew with this one.
 
I would like to write a LISP that will create layers within an open drawing based on a proposed buildings max story height while factoring in the possibility of a basement floor and/or split ground floor (upper/Lower). The layer names are floor specific and would be as follows:
 
x =floor number (-1 = Basement, 0 =Ground, 1 = First etc)
NLP x Walls
NLP x Windows
NLP x Rooms
NLP x Balcs
NLP x Detailing
(one set of layers per floor)
 
Setq: user inputs
basement (Yes/No)
Splitgrnd (Yes/No)
floorno (numeric value based on total number of floors)
 
Setq: program
floornoabsolute (based on user inputs to return number of top floor)
 
n.b. I appreciate that the routine is probably cumbersome and could be streamlined but please ignore this for now as I am using it as a teaching aid and will learn how to do this in due course, for now I would just like to know a few things that I am struggling with.
 
My LISP so far:
(defun c:NLPADDLAYERSTEST ( / floorno basement splitgrnd floornoabsolute)
  (initget 1 "Yes No")
  (setq basement (getkword "\nDoes the Scheme have a basement? (Yes/No): ")
        )
  (cond
    ((= basement "Yes") (command "layer" "n" "NLP -1 Walls" "n" "NLP -1 Windows" "n" "NLP -1 Rooms" "n" "NLP -1 Balcs" "n" "NLP -1 Detailing" ""))
    )
  (initget 1 "Yes No")
  (setq splitgrnd (getkword "\nIs the ground floor split into upper and lower? (Yes or No): ")
        )
  (if (= splitgrnd "Yes")
    (command "layer" "n" "NLP 0U Walls" "n" "NLP 0U Windows" "n" "NLP 0U Rooms" "n" "NLP 0U Balcs" "n" "NLP 0U Detailing" "n" "NLP 0L Walls" "n" "NLP 0L Windows" "n" "NLP 0L Rooms" "n" "NLP 0L Balcs" "n" "NLP 0L Detailing" "")
    (command "layer" "n" "NLP 0 Walls" "n" "NLP 0 Windows" "n" "NLP 0 Rooms" "n" "NLP 0 Balcs" "n" "NLP 0 Detailing" "")
    )
  (initget 1)
  (setq floorno (getreal "\nHow many stories in the proposed scheme? (max if multiple buildings): ")
        floornoabsolute (cond
                          ((and (= basement "No") (= splitgrnd "No") ("!floorno"-1)))
                          ((and (= basement "Yes") (= splitgrnd "Yes") ("!floorno"-3)))
                          ((and (= basement "Yes") (= splitgrnd "No") ("!floorno"-2)))
                          ((and (= basement "No") (= splitgrnd "Yes") ("!floorno"-2)))
                          )
Unwritten part of program
        )
)
 
Question 1
 
In the floornoabsolute set of conditions what would be the correct syntax in order to have the program return a value of floorno - number. As you can see I have it as ("!floorno"-2) but beleive that is incorrect.
 
Question 2
 
Would the following be the correct way to set a value for floornoabsolute? (excluding the fact that the part from the previous question is wrong)
(setq floornoabsolute  (cond
((and (= basement "No") (= splitgrnd "No") ("!floorno"-1)))
((and (= basement "Yes") (= splitgrnd "Yes") ("!floorno"-3)))
((and (= basement "Yes") (= splitgrnd "No") ("!floorno"-2)))
((and (= basement "No") (= splitgrnd "Yes") ("!floorno"-2)))
                          )
 
Question 3
As I am still learning my initial approach to the rest of the code was going to be; set up a text file/s with the layer names in and have the program follow it until x(floor number) = floornoabsolute. The reason for this is I don't know enough yet to decipher any posts pertaining to Sequential numbering LISPs.
 
Is there a relatively simple way to tell the program to create a set of layers, lets say NLP x walls, where x starts at 1 and progresses sequentially until x= floornoabsolute?
 
Thanks in advance for any help.
 
Regards
 
Steve
回复

使用道具 举报

4

主题

2143

帖子

2197

银币

限制会员

铜币
-24
发表于 2022-7-5 17:24:30 | 显示全部楼层
Please read the Code Posting Guidelines and edit your Code to be included in Code Tags.[NOPARSE]
  1. Your Code Here[/NOPARSE]
=
  1. Your Code Here
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 18:00:55 | 显示全部楼层
Look into repeat
 
  1. (setq num (getint "Number of floors"))(setq x (+ num 1))(repeat  num(setq fl (rtos (setq x (- x 1))2 0))(command "-layer" "m" (strcat "NPL" fl "Walls") "m" (strcat "NPL" fl "Windows") ""))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 14:07 , Processed in 0.491023 second(s), 69 queries .

© 2020-2025 乐筑天下

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