Baber62 发表于 2022-7-6 07:24:37

偏移到特定图层

你好
 
需要这个例程的帮助,它会偏移到选定的层,但是我需要添加编码来删除它偏移的原始对象。
 
编码如下所示:
 


;; OL.lsp
;; Offset-to-Layer = Offset an entity a specified distance, and Change the new entity to a specified Layer.
;; At first use, offers current Offset Distance and current Layer as defaults;
;; subsequently, offers this routine's previously-used Offset-to-Layer Distance (even if ordinary Offset
;; distance has been changed) and Layer-to-change-to as defaults.
;; by Kent Cooper, August 2008
(defun C:OL (/ offlaytemp offent)
(initget 134)
(setq
offlaydist
(cond
(
(getdist
(strcat
"\nOffset-to-Layer distance or <"
(cond
((numberp offlaydist) (rtos offlaydist))
((= (getvar 'offsetdist) -1) "Through")
((rtos (getvar 'offsetdist)))
); end cond
">: "
); end strcat
); end getdist
); end first cond test
(T (if (not offlaydist) (getvar 'offsetdist) offlaydist))
); end cond
offlaytemp
(getstring
(strcat
"\nLayer to Offset to <"
(if offlay offlay (getvar 'clayer))
">: "
); end strcat
); end getstring
offlay
(cond
((/= offlaytemp "") offlaytemp)
(offlay)
(T (getvar 'clayer))
); end cond
); end setq
(while
(not
(while
(not
(and
(setq offent (ssget ":S" '((0 . "LINE,ARC,CIRCLE,ELLIPSE,LWPOLYLINE,SPLINE,XLINE,RAY"))))
(= (cdr (assoc 70 (tblsearch "layer" (cdr (assoc 8 (entget (ssname offent 0))))))) 0); 0 for Unlocked, 4 for Locked
); end and
); end not
(prompt "\nSelected Entity cannot be Offset, or is on a Locked Layer; try again: ")
); end while
); end not
(command "_.undo" "_be")
(command
".offset" offlaydist offent pause ""
".chprop" "l" "" "la" offlay ""
); end command
(command "_.undo" "_e")
); end while
); end defun
(princ "\nType OL to Offset to Layer.")
(princ)


 
任何帮助都将不胜感激。

Lee Mac 发表于 2022-7-6 07:29:45

为什么不使用标准偏移命令的“Layer”和“Erase”选项?
 
Specify offset distance or Erase/Layer] <Through>:
 
PS:请编辑您的帖子,并用代码标签附上您的代码:
 
[突出显示][不突出]
Your code here

Baber62 发表于 2022-7-6 07:33:28

嗨,李,
 
我该如何在lisp例程中使用它?
 
 
 
“数学在于用最不明显的方式证明最明显的事情。”--乔治·波利亚

Lee Mac 发表于 2022-7-6 07:36:49

 
下面是一个自动设置“偏移”命令选项以擦除原始对象并偏移到当前层的示例:
 
使用offset命令的现有选项可以避免为此任务重新发明轮子。
在调用偏移命令以偏移到您选择的层之前和之后,可以很容易地添加其他代码来设置/重置当前层。

teknomatika 发表于 2022-7-6 07:40:23

 
李,
 
考虑到这个想法,我如何应用于,使具有厚度的多段线可以偏移到变量plinewid值的一半?
我不知道还有什么方法可以在不以中心为中心的情况下绘制具有厚度的多段线,因此这将是一个这样做的机会。
为了更好地理解,我附上了一张照片。
 
(defun c:ofpw (/ pw )
   (setq pw (/(getvar "plinewid") 2))
(setq pw (/ pw 2))
(command "_.offset" pw "_E" "_Y" "_L" "_C");; not work
   (while (< 0 (getvar 'cmdactive)) (command "\\"))
   (princ)
)

Baber62 发表于 2022-7-6 07:42:14

您好,teknomatika,
 
我有另一个代码,我用它来调整各种多段线的厚度,但你的想法如果进一步发展,可能会证明是有用的,即有一个偏移,然后调整线的厚度。也许有人会把代码组合在一起。
 


(Defun c:Plw (/ s ss sn i)



(if (setq s(ssadd)      
ss (ssget "_x" '((0 . "*POLYLINE") (8 . "Estate - AAT,Estate - Hatched area,Estate - Lockable gate, Estate - SYL")))    ;<<<<< Enter layer names separated by comma
)   
(progn      
        (repeat (setq i (sslength ss))   
(setq sn (ssname ss (setq i (1- i))))   
(if (not (eq (cdr (assoc 100 (reverse (entget sn))))            
"AcDb3dPolyline"         
        )      
)      
(ssadd sn s)   
        )      
)      
(if (> (sslength s) 0)   
(command "_.pedit" "_m" s "" "w" 0.2 "")      
        )      
;(princ "\n .... ")      
;(princ (strcat "Number of Polylines changed : "
            " < "            
;(itoa (sslength s))             " > "         
;                )      
;        )   
)   
;(princ "\n Couldn't find any 2D polyline !!")
)
(princ)
)

Lee Mac 发表于 2022-7-6 07:46:45

李,
 
确实如此。
再次感谢你。

teknomatika 发表于 2022-7-6 07:49:36

李,
 
这很好,但我仍在努力让它做我想做的事情,那就是做一个偏移,擦除原始线,然后改变偏移线的图层和线宽。。。任何帮助都将不胜感激。
 
 
“数学在于用最不明显的方式证明最明显的事情。”--乔治·波利亚

Baber62 发表于 2022-7-6 07:52:16

 
不客气!
 
 
通过在调用offset命令之前将当前层设置为所需层(CLAYER系统变量),然后在评估offset命令后重置当前层,可以很容易地使用我的现有代码实现层分配。
 
但是,在调用offset命令之前,设置“线宽”(我假设您的意思是LWPolyline width)可能需要进行限制选择,然后通过在offset命令之后调用entlast函数对偏移实体进行操作。
 
到目前为止你有什么?

Lee Mac 发表于 2022-7-6 07:54:15

李,
 
没有太多的时间看例行程序,还不够精通lisp。。。仍在学习诀窍。这就是为什么我必须使用两个独立的例程,一个是偏移层,然后运行plw来改变厚度。试图调整编码,但没有成功。经历了大约六种不同的编码,但都没有成功。还查找了您在第一个命令行中输入的代码,但两者都没有深入了解。
 
 
 
“数学在于用最不明显的方式证明最明显的事情。”--乔治·波利亚
页: [1] 2
查看完整版本: 偏移到特定图层