乐筑天下

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

[编程交流] First steps in AutoLISP - too

[复制链接]

3

主题

8

帖子

5

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-5 15:29:42 | 显示全部楼层 |阅读模式
Hello
 
My first post here, so I will start with a brief introduction. I'm an engineering surveyor working in BricsCAD 18 (it's not listed as an option in this forum's registration form), most of my work is editing/tidying drawings exported from other software. I also do a fair bit of data manipulation in spreadsheets, and LISP is the next thing I want to get into.
 
Unfortunately I have very limited time for troubleshooting. I wrote my first script today and guess what - too few / too many arguments. Can anyone cast their eye please?
 
  1. (defun c:leveltext1103 (datum levpoint ydatum ypoint levdistance)(setq datum (getpoint "\nDatum line:"))(setq point (getpoint "\nSurvey point:"))(setq ydatum (cadr (datum)))(setq ypoint (cadr (levpoint)))(setq levdistance (rtos (* 2 (- point datum) 2 2)));setq(command "text" levpoint "0.15" "0" levdistance ""));defun
The code is intended to produce a piece of text based on a scaled measurement of the y distance between two points on paperspace. Naturally this is just a dimension but I will later need to apply offsets etc to the calculation. I tried a few changes already and still get the error. I hope this is enough information for someone to resolve. Thanks in advance.
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 15:45:45 | 显示全部楼层
  1. (defun c:leveltext1103 ( [b][color="red"]/[/color][/b] datum levpoint ydatum ypoint levdistance)
回复

使用道具 举报

18

主题

1529

帖子

973

银币

中流砥柱

Rank: 25

铜币
649
发表于 2022-7-5 15:58:05 | 显示全部楼层
Actually there are more than 5 issues with the code.
  1. (defun c:leveltext1103 ( / datum levpoint ydatum ypoint levdistance) (setq datum (getpoint "\nDatum line:")) (setq levpoint (getpoint "\nSurvey point:")) (setq ydatum (cadr datum)) (setq ypoint (cadr levpoint)) (setq levdistance    (rtos (* 2 (- ypoint ydatum)) 2 2) ) ;setq (command "_.text" "_non" levpoint "0.15" "0" levdistance) (princ)) ;defun
回复

使用道具 举报

3

主题

8

帖子

5

银币

初来乍到

Rank: 1

铜币
15
发表于 2022-7-5 16:08:25 | 显示全部楼层
Thank you both for your rapid responses, that's great.
 
I was going by this:
taken from the bottom of http://www.afralisp.net/autolisp/tutorials/the-define-function.php
Is the advice on afralisp a bit oversimplified or am I missing something?
I've put red colour on any of your edits which I noticed. Coding is not forgiving, is it... Your code works! Did you make any more edits which I am missing?
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-5 16:20:54 | 显示全部楼层
Re testing globally
 
  1. ;(defun c:leveltext1103 ( / datum levpoint ydatum ypoint levdistance)(defun c:leveltext1103 ( )
 
Sometimes though doing with global you will need to type say (setq datum nil) on command line to clear a variable.
回复

使用道具 举报

66

主题

1552

帖子

1514

银币

后起之秀

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

铜币
325
发表于 2022-7-5 16:39:06 | 显示全部楼层
Thank you both for your rapid responses, that's great. 
 
I was going by this:
 
taken from the bottom of http://www.afralisp.net/autolisp/tutorials/the-define-function.php
Is the advice on afralisp a bit oversimplified or am I missing something?

 
Global variables.. well I hope you understand:
 
(defun c:something (  )
 
This means you didn't used global variables either,
Main issue with your code is that you excluded '/' so your function became this structure:
 
(defun example ( ex1 ex2 ex3 )
 
where to call it you must provide arguments to it, like:
(example "string" 1 (list "this" "is" "a list"))
 
so if it was:
(defun example ( / ex1 ex2 ex3 )
the call would be just:
(example)
because now 'ex ex2 and ex3' are variables that the example functions uses inside.
 
Yeah afralisp's examples are oversimplified and thats great for someone new to learn easily LISP.
I'd suggest checking Lee Mac's tutorials, Localising Variables is related to your problem.
Tho each tutorial requires very careful reading and re-reading it n-times, but you won't regret it.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-14 00:19 , Processed in 0.678040 second(s), 75 queries .

© 2020-2025 乐筑天下

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