乐筑天下

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

[编程交流] Lisp erases snap settings- Ple

[复制链接]

9

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-5 16:41:40 | 显示全部楼层 |阅读模式
Hi guys,
 
I have a beautifull lisp that I found that creates lines at specific devisions from the user , my snap settings are usually on ( I select all my object snap so I can pick every point as my cusor change ) but when I want to use my lisp again I need to select all the object snap again.
How can I keep my setting so it will not erase them?
LINE_DIV.lsp
回复

使用道具 举报

27

主题

113

帖子

90

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
132
发表于 2022-7-5 17:00:28 | 显示全部楼层
You could add an command to fix the osnap again. I wouldn't know what changes the settings, but you can restore it
 
  1. (command "-osnap" "endpoint,midpoint,center,node,quadrant,tangent")
 
Add and/or delete the snaps you want, and place this line of code somewhere (or at the end) of your lisp.
回复

使用道具 举报

9

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-5 17:09:44 | 显示全部楼层
Hi OMEGA-ThundeR,
 
Thank you for responding but it didn't solve my problem. I added your code to last of my lisp and it seems to erase the setting again.
maybe something is missing in your code, please check.
I don't know how to check or write lisps.
 
Thank you.
回复

使用道具 举报

27

主题

113

帖子

90

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
132
发表于 2022-7-5 17:11:54 | 显示全部楼层
Hmz.. strange... i shall test the code myself... brb
回复

使用道具 举报

27

主题

113

帖子

90

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
132
发表于 2022-7-5 17:28:53 | 显示全部楼层
Ok, i guess it has something to do with the 'osmode' variable  and that will probably fix (or is) the problem but i don't know how to.
 
But after adding the line of code after;
  1. (setvar 'osmode 16384)
 
(somewhere in the first few lines of code in the lisp)  i kinda got it to fix the snappoints again.  
 
so it would become something like this:
  1.            (setvar 'osmode 16384)(command "-osnap" "endpoint,midpoint,center,node,quadrant,tangent")          (setq spaces  (test spaces1 ())
 
It's an dirty fix i guess.  Someone else might give a better sollution.
回复

使用道具 举报

9

主题

23

帖子

14

银币

初来乍到

Rank: 1

铜币
45
发表于 2022-7-5 17:37:24 | 显示全部楼层
Thank you OMEGA-ThundeR,
 
I found a solution.
 
here is the fixed code.
 
  1. (defun c:somefunc  (/ f curlayer curosmode ent exit a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z)(defun *error* (msg)(setvar 'osmode curosmode)(princ msg)(princ));defun error (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))              vlaObj2   (vlax-ename->vla-object (car (entsel)))              curlayer  (getvar 'clayer)              curosmode (getvar 'osmode)              spaces1   (getreal "\nEnter number of spaces: "))   (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")         (T          (setvar 'clayer (cdr (assoc 8 (entget ent))))          (setvar 'osmode 16384)          (setq spaces  (test spaces1 ())                testlst (vl-sort                          (apply                            'append                            (mapcar                              '(lambda (y)                                 (mapcar '(lambda (x) (append (append (list (distance x y)) (list x)) (list y)))                                         (list (vlax-curve-getStartPoint vlaObj1)                                               (vlax-curve-getEndPoint vlaObj1))))                              (list (vlax-curve-getStartPoint vlaObj2)                                    (vlax-curve-getEndPoint vlaObj2))))                          '(lambda (x y) (< (car x) (car y))))                a       (cdar testlst)                b       (cdr (apply 'append                                    (car (mapcar '(lambda (y)                                                    (mapcar '(lambda (x)                                                               (if (not (or (equal (cadar testlst) (cadr x) y)                                                                            (equal (caddar testlst) (caddr x) y)                                                                            (equal (cadar testlst) (caddr x) y)                                                                            (equal (caddar testlst) (cadr x) y)))                                                                 x))                                                            testlst))                                                 (list 1e-15))))))          (command "._undo" "_begin")          (test2 a b spaces1 spaces)          (command "._undo" "_end")          (initget "Yes No")          (setq f (cond ((getkword "\nFLip lines [Yes/No] : "))                        ("No")))          (cond ((wcmatch f "Yes,Y")                 (command "._undo" 1)                 (setq z (last a))                 (setq a (cons (car a) (cdr b)))                 (setq b (cons (car b) (list z)))                 (test2 a b spaces1 spaces))                (T ()))))) (setvar 'clayer curlayer) (setvar 'osmode curosmode)(*error*))(defun test  (x y) (cond ((< x 1) y)       (T (test (fix (- x 1)) (cons (fix x) y)))))(defun test2  (a b c d) (mapcar '(lambda (x y) (command-s "._pline" x y ""))         (mapcar '(lambda (x) (polar (car a) (angle (car a) (cadr a)) (* (/ (distance (car a) (cadr a)) c) x)))                 (if (not (zerop (rem c (fix c))))                   d                   (cdr (reverse d))))         (mapcar '(lambda (x) (polar (car b) (angle (car b) (cadr b)) (* (/ (distance (car b) (cadr b)) c) x)))                 (if (not (zerop (rem c (fix c))))                   d                   (cdr (reverse d))))))
回复

使用道具 举报

17

主题

1274

帖子

25

银币

后起之秀

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

铜币
260
发表于 2022-7-5 17:48:54 | 显示全部楼层
 
I modified the start of your code removing "EXIT" in defun as you shouldn't redefine autolisp functions and it wasn't used in your code anyway.  I added an *error* function and localized it by adding *error* to the defun to make sure the variables were reset while not affecting *error* for any other lisp.  Then moved setting curosmode & curlayer to the top outside the while loop so it would only be set once.
 
Try replacing the start of your code with:
  1. (defun c:somefunc  (/ *error* f curlayer curosmode ent a b spaces spaces1 testlst vlaobj1 vlaobj2 x y z) (defun *error* (msg)              (setvar 'osmode curosmode)              (setvar 'clayer curlayer)              (princ msg)              (princ) );defun error (setq curosmode (getvar 'osmode)              curlayer  (getvar 'clayer) ) (while (setq vlaObj1   (vlax-ename->vla-object (setq ent (car (entsel))))              vlaObj2   (vlax-ename->vla-object (car (entsel)))              spaces1   (getreal "\nEnter number of spaces: "))   (cond ((or (minusp spaces1) (< spaces1 1)) "Spaces should be greater than 1")
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-13 13:30 , Processed in 0.460760 second(s), 77 queries .

© 2020-2025 乐筑天下

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