乐筑天下

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

[编程交流] Scaling LISP - can you guys pl

[复制链接]

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-6 09:11:05 | 显示全部楼层 |阅读模式
Hey guys,
 
Ive just put together a little scaling LISP which allows the user to select objects (in my case its a title block for a 2D DRG) and scale them accordingly.
 
So my application is...
 
For 2D working DRGs - we have a title block inserted at whatever scale the DRG was originally created at - the user will wish to re-scale this title block... but the DIMSCALE, LTSCALE and text will need to also be scaled accordingly.  We also have a field (ATTRIBUTE) within the title block which needs to note what scale the DRG is at.
 
So... i have created this routine - which does work... but i feel it requires a little too much input.  Heres what is required by the user as they run this routine...
 
1.  Run command. SSC
2.  Select objects to scale. Title block and material list
3.  Enter current scale. 50
4.  Enter desired scale. 25
5.  Enter scale as it currently appears in title block. 1:50
6.  Enter scale as it will appear in title block.  1:25
 
As you can see - there is a bit of semi-repetition required by the user (though it is much simpler than modifying all the scale values manually).
 
I basically would like to eliminate steps 5 and 6 - have those inputs be read from steps 3 and 4 if possible.
 
It would also be fantastic if the data enter by the user in step 3 could be read automatically (maybe read it from the original DIMSCALE value - though this could be risky if the initial DIMSCALE was not set correctly).
 
Here is the code:
 
  1. (DEFUN C:ssc ()(setq ocmd (getvar "CMDECHO"))(prompt "\nSelect Title Block, Mark and Material List to be re-scaled... ")(setq sscpt1 '(0 0 0))(setq sscsset1 (ssget))(SETQ ssccs (getreal "\nEnter Current Scale : "))(SETQ sscds (getreal "\nEnter Desired Scale : "))(COMMAND "scale" sscsset1 "" sscpt1 (/ sscds ssccs))(COMMAND "dimscale" sscds)(COMMAND "ltscale" (* sscds 10))(COMMAND "-style" "PDC_Prosteel" "isocp.shx" (* sscds 3.5) "1" "0" "NO" "NO")(SETQ ssctso (getstring "\nEnter Current Scale as it appears in title block (1:5, 1:10, 1:50, etc): "))(SETQ ssctsn (getstring "\nEnter Desired Scale as it will appear in title block: "))(COMMAND "-attedit" "n" "n" "pdctitle" "pdcscale" "" ssctso ssctsn)(COMMAND "graphscr")(setvar "CMDECHO" ocmd)(princ))
 
Thanks a lot for any help dudes.
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 09:24:29 | 显示全部楼层
You can avoid prompting the user for base scale by getting this from the title block entity - since you know the relation between drawing scale and block's insertion scale you can calculate the required value. Also may be safe to filter out entities other than blocks at selection:
 
  1. (setq sscsset1 (ssget '((0 . "INSERT"))))(setq ssccs (cdr (assoc 41 (entget (ssname sscpt1 0)))))(setq ssccs ([color=black]/[/color]ssccs BaseBlockScale))[color=blue]   ;add your formula here[/color]
 
After that, since you have the base scale (read), respectively target scale (input) you can convert those to strings:
 
  1. (setq ssctso (strcat "1:" (itoa ssccs))     ssctsn (strcat "1:" (itoa (fix sscds))))
 
This way may get rid of 3 prompts.
 
Regards,
Mircea
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-6 09:31:51 | 显示全部楼层
Thanks a lot for the reply mircea.  I'm afraid im not at my computer right now so I can't test it out.
 
Can you please help me out by inserting your code into mine? I'm not really sure where it should all go.
 
Thanks again, ill let you know if I have any luck.
回复

使用道具 举报

35

主题

2471

帖子

2447

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
174
发表于 2022-7-6 09:37:05 | 显示全部楼层
You’re welcome!
I’m sure that you will benefit more if will try to fix the code by yourself. Just do one change at a time and test the effect.
 
Regards,
Mircea
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-6 09:48:12 | 显示全部楼层
No problem Mircea,
 
Thanks again.
 
I'll post back in a few hours and let you know how much success I have.
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-6 09:49:09 | 显示全部楼层
Hello again,
 
So i ended up getting it to work quite well... though i havent quite been able to get the routine to read the current scale - little trickier.
 
I managed to tweak the code you gave me to read the initial inputs and compile the string (had to replace ITOA with RTOS - is that correct?).
 
One of the problems with reading the scale from the existing block is that the title block is not made up of just 1 block - it is a few different blocks, some lines, text, etc.  So i will try to get the routine to read the scale from one of the blocks (select > blockname?).
 
So, with your help Mircea - i have managed to eliminate the need for steps 5 and 6... hopefully ill be able to get rid of step 3 soon too.
 
Here is the current code...
 
  1. (DEFUN C:ssc ()(setq ocmd (getvar "CMDECHO"))(prompt "\nSelect Title Block, Mark and Material List to be re-scaled... ")(setq sscpt1 '(0 0 0))(setq sscsset1 (ssget))(SETQ ssccs (getreal "\nEnter Current Scale : "))(SETQ sscds (getreal "\nEnter Desired Scale : "))(COMMAND "scale" sscsset1 "" sscpt1 (/ sscds ssccs))(COMMAND "dimscale" sscds)(COMMAND "ltscale" (* sscds 10))(COMMAND "-style" "PDC_Prosteel" "isocp.shx" (* sscds 3.5) "1" "0" "NO" "NO")(setq ssctso (strcat "1:"(rtos ssccs)))(setq ssctsn (strcat "1:"(rtos sscds)))(COMMAND "-attedit" "n" "n" "pdctitle" "pdcscale" "" ssctso ssctsn)(COMMAND "graphscr")(setvar "CMDECHO" ocmd)(princ))
 
 
Thanks again.
回复

使用道具 举报

106

主题

1万

帖子

101

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1299
发表于 2022-7-6 09:57:22 | 显示全部楼层
Can I ask a dumb question why are you not using layouts with your title block there ? draw at 1:1 plot at whatever scale you want. Its a better way to go than plotting from modelspace.
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-6 10:09:23 | 显示全部楼层
Hi BIGAL,
 
Good question mate - the software package were using with AutoCAD was setup by another drafting office, so we are pretty much following their procedure.  Its for steel detailing, a model is created in one .DWG, then the 2D DRGs are created (exported from the model) in a lot of other .DWGs.  The title block is all inserted as part of the export procedure... but the scale is always set as a default (1:10).  The other office scale by manually editting each setting (as listed in first post) - i figured creating a routine to modify all settings at once would be good.  And thanks to the help of Mircea... thats what i have.
 
Here is the final code - all working good. Required steps are as follows:
 
1. Run command. SSC
2. Select objects to scale. Title block and material list
4. Enter desired scale. 25
 
  1. (DEFUN C:ssc ()(setq ocmd (getvar "CMDECHO"))(prompt "\nSelect Title Block, Mark and Material List to be re-scaled... ")(setq sscpt1 '(0 0 0))(setq sscsset1 (ssget))(setq ss (ssget "X" (list (cons 0 "insert")(cons 2 "pdctitle"))))(setq ename (ssname ss 0))(setq data (entget ename))(setq ssccs (cdr (assoc 41 data)))(SETQ sscds (getreal "\nEnter Desired Scale : "))(COMMAND "scale" sscsset1 "" sscpt1 (/ sscds ssccs))(COMMAND "dimscale" sscds)(COMMAND "ltscale" (* sscds 10))(COMMAND "-style" "PDC_Prosteel" "isocp.shx" (* sscds 3.5) "1" "0" "NO" "NO")(setq ssctso (strcat "1:"(rtos ssccs)))(setq ssctsn (strcat "1:"(rtos sscds)))(COMMAND "-attedit" "n" "n" "pdctitle" "pdcscale" "" ssctso ssctsn)(COMMAND "graphscr")(setvar "CMDECHO" ocmd)(princ))
 
 
Thanks so much for your help - saves a lot of setup time for the draftees.
 
Cheers.
回复

使用道具 举报

77

主题

298

帖子

232

银币

后起之秀

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

铜币
394
发表于 2022-7-6 10:17:40 | 显示全部楼层
hi again guys,
 
im afraid ive run into a few issues with this routine and will have to tweak it further.  just wondering if anyone can please help me sort these issues out.
 
The problem i am having is that the scaling routine will only work when the DRGs units are set to zero decimal places.  The process where the routine needs to find and replace a text string in a block relies on an exact match and the output must be to zero (or one decimal place in the case of half scales).
 
the routine will run perfectly when the DRGs units are set to zero decimal places AND the scale is a whole/round number.
 
- IF the DRGs units are set to anything but zero decimal places... the routine will only partially work, the rescaling will be completed but the title block will not be updated because of the mis-match between the value in the title block having zero decimal places and the entered value been read as having the same ammount of decimal places as the DRG.
 
- IF the DRG units are set to ZERO decimal places and a half scale is used (eg:  7.5)... the routine will only partially work, the rescaling will be completed but the title block will be updated incorrectly.  The value in the scale field in the title block will be rounded to the neared round number.
 
 
Can anyone please help me sort this out?
 
Thanks for any help.
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-7 05:26 , Processed in 0.357555 second(s), 70 queries .

© 2020-2025 乐筑天下

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