乐筑天下

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

[编程交流] need help shortening my '

[复制链接]

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 09:47:14 | 显示全部楼层 |阅读模式
  1. (defun c:test ( / LayerLocked LayerFrozen)(vl-load-com)    (setq      acadObject       (vlax-get-acad-object)      acadActiveDocument    (vla-get-ActiveDocument acadObject)    );;;  Modify Layer Properties (setq   acadLayers (vla-get-Layers acadActiveDocument) ) (vlax-for eachLayer acadLayers   (if     (= (vla-get-Lock eachLayer) :vlax-true)   (progn     (setq LayerLocked (cons eachLayer LayerLocked))     (vla-put-Lock eachLayer :vlax-false)       )   ) ) (vlax-for eachLayer acadLayers   (if     (= (vla-get-Freeze eachLayer) :vlax-true)     (progn(setq LayerFrozen (cons eachLayer LayerFrozen))(vla-put-Freeze eachLayer :vlax-false)          )   ) );;;  Restore Layers(foreach eachLayer LayerLocked  (vla-put-Lock eachLayer :vlax-true))(foreach eachLayer LayerFrozen  (vla-put-Freeze eachLayer :vlax-true))(princ))
 
 
I need help figuring out how to combine two (vlax-for)
and
the last two (foreach) statments.
 
I have tried (and), (and or) (progn) and every combination until I am so darn confused I can't think straight.
 
No matter my combination it wants to juggle the results.
 
Breaking it down separatly as above works fine but I want to learn how to combine these (for) statements.
 
Thanks for any advise
回复

使用道具 举报

8

主题

81

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-6 09:51:07 | 显示全部楼层
Hint: You can iterate through the layer collection once by placing both of your conditions in one vlax-for statement.
       Also, look at replacing if/progn with and.
 
       As for combining your foreach statements, why not use a mapcar statement?
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 09:55:03 | 显示全部楼层
Hi jvill
 
yes, I am wanting to place both of my conditions into one vlax-for statement but when I do, I lose control of my layers.
 
If I replace the if/progn with and
will this not be looking for both conditions, frozen and locked on one layer?
 
My layers can be a combination of:
 
both thawed and unlocked
one thawed and one locked
one unlocked and one frozen
etc...  (any combination)
 
 
If I just use (and) doesn't this mean that the layer has to be both locked and frozen?
回复

使用道具 举报

8

主题

81

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-6 09:57:15 | 显示全部楼层
Keep the conditions separated under the same vlax-for statement.
Example:
  1. (and(this is true)(do this)(do this too))(and(this is true)(do this)(do this too))
回复

使用道具 举报

8

主题

81

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-6 10:02:58 | 显示全部楼层
  1. When you wanna compare your solution, scroll down:(vlax-for eachLayer acadLayers(and (= (vla-get-Lock eachLayer) :vlax-true) (setq LayerLocked (cons eachLayer LayerLocked)) (vla-put-Lock eachLayer :vlax-false) )(and (= (vla-get-Freeze eachLayer) :vlax-true) (setq LayerFrozen (cons eachLayer LayerFrozen)) (vla-put-Freeze eachLayer :vlax-false) ));;;and the mapcar solution:(mapcar(function (lambda (locked frozen) (vla-put-lock locked :vlax-true)(vla-put-freeze frozen :vlax-true)))LayerLocked LayerFrozen)
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 10:03:19 | 显示全部楼层
jvill
 
I can't thank you enough for the method you use in helping me.  (I come here looking for hints and techniques, not quick easy answers)  but sometimes seeing my failed code written correctly after hours of playing with it really helps.
 
I nailed the (vlax-for) (and) (and)...  but not without your hit in your second post
 
I failed at getting the mapcar to work...  I couldn't figure out the lambda function by the example in help, with what I was trying to do,,,  (I couldn't connect the dots)
 
Here is my failed attempt just to show I was getting close
 
 
  1. (defun c:test ( / LayerLocked LayerFrozen)(vl-load-com)    (setq      acadObject       (vlax-get-acad-object)      acadActiveDocument    (vla-get-ActiveDocument acadObject)    );;;  Modify Layer Properties (setq   acadLayers (vla-get-Layers acadActiveDocument) ) (vlax-for eachLayer acadLayers   (and     (= (vla-get-Lock eachLayer) :vlax-true)     (setq LayerLocked (cons eachLayer LayerLocked))     (vla-put-Lock eachLayer :vlax-false)   )      (and     (= (vla-get-Freeze eachLayer) :vlax-true)     (setq LayerFrozen (cons eachLayer LayerFrozen))     (vla-put-Freeze eachLayer :vlax-false)   )  );;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;  Restore Layers ;(mapcar   ;'(lambda ()  (foreach eachLayer LayerLocked    (vla-put-Lock eachLayer :vlax-true)  (foreach eachLayer LayerFrozen    (vla-put-Freeze eachLayer :vlax-true)         )  )     (princ))
 
as you can see I gave up on the mapcar and lambda and just used two foreach statements.
 
seeing your example and then your code really helped me, thank you...  I was getting brain tired and frutrated.
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 10:07:15 | 显示全部楼层
what does this mean?
 

[code] (mapcar(function (lambda (locked frozen) (vla-put-lock locked :vlax-true)(vla-put-freeze frozen :vlax-true)))LayerLocked LayerFrozen
回复

使用道具 举报

8

主题

81

帖子

45

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
76
发表于 2022-7-6 10:10:58 | 显示全部楼层
 
Anytime cadman..i like trying it before being given the answer as well.
I'm passing the lists to mapcar there.
Here's a small example with the mapcar statement.
 
  1. (mapcar'(lambda (Locked Frozen)  (do something to Locked)  (do something to Frozen))(Locked List) (Frozen List))
回复

使用道具 举报

23

主题

117

帖子

87

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
123
发表于 2022-7-6 10:13:33 | 显示全部楼层
never mind I figured it out....
 
I tell you, I don't think I would have solved the mapcar lambda on my own...
I am looking at and still don't understand it...  I will need to study this...
 
Thanks again
回复

使用道具 举报

54

主题

3755

帖子

3583

银币

后起之秀

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

铜币
438
发表于 2022-7-6 10:17:29 | 显示全部楼层
Just for fun, here's another way...
 
  1. (defun foo (/ lst) (vlax-for x (vla-get-layers (vla-get-activedocument (vlax-get-acad-object)))   (and (eq (vla-get-lock x) :vlax-true)        (setq lst (cons (list x 'Lock :vlax-true) lst))        (vla-put-lock x :vlax-false)   )   (and (eq (vla-get-freeze x) :vlax-true)        (setq lst (cons (list x 'Freeze :vlax-true) lst))        (vla-put-freeze x :vlax-false)   ) ) ;; DO STUFF (foreach x lst (apply (function vlax-put-property) x)))
回复

使用道具 举报

发表回复

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

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

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

GMT+8, 2025-3-7 00:39 , Processed in 1.187488 second(s), 72 queries .

© 2020-2025 乐筑天下

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