MarcoW 发表于 2022-7-6 12:00:01

计算新i的问题

啊。。
 
这是我的代码:
 

(defun c:test (/ )
(setq entity (car (entsel "\nSelect a block: ")))
(if entity
   (progn
   (setq data (entget entity))
   
   (if (= (cdr (assoc 0 data)) "INSERT")
(progn   
(setq block_ins (cdr (assoc 10 ent_data))
   
block_scx (cdr (assoc 41 ent_data))
   
block_rot (cdr (assoc 42 ent_data))
   
block_rot (cdr (assoc 50 ent_data))
)

(setq point1 (polar block_ins (+ block_rot (* 0.5 pi)) 150))
(command "_.insert" "w1" point1 block_scx block_scy block_rot)

)
   )
   )
)
(princ)
)

 
这就是为什么会发生:在一个图形中,我有一个块,第一个或原点块。我在它旁边再划一个街区,要么在同一条基线上离它不远,要么在同一条基线上离它不远。两者之间的距离应为150mm。
 
我想没有什么困难,但我一直坚持这样做:
 
 
我会在其中添加带有initget/keyword的选项(左/右),但我甚至没有走那么远。
 
有人能把我踢向正确的方向吗?我不需要完整的Lisp程序,只是解释如何做到这一点。
 
谢谢
马可。

David Bethel 发表于 2022-7-6 12:12:06

ent_数据不应该是数据吗-大卫

MarcoW 发表于 2022-7-6 12:20:06

 
哎呀。。。是的:我想我是真的瞎了。
这个呢?
 

block_rot (cdr (assoc 42 ent_data))
   
block_rot (cdr (assoc 50 ent_data))


 
相同变量名的两倍。。。。
 
我现在又在做了。。。
Tnx的回复。

MarcoW 发表于 2022-7-6 12:32:54

这不是最方便的发帖方式,但要求“内联”这对我来说很好。
 

; anyone that can help me?
; thank you
; I want to place a block 150mm beside an allready placed block.
; Same angle, same scale.
; But I want to reach the goal not by getting complete routine.
; So only the kick in my %$# is enough (I hope)
;
; Some parts I base on another routine, so not all of it is clear to me.
; I have marked them with a "?"...

(defun c:test (/ ); creating the function -> I must fill in the local variables when ready wrinting routine

; set some variables
(setqentity (car (entsel "\nSelect a block: ")) ; get the info from the block allready placed
data (entget entity)    ; get "?" out of entity and put it in data

block_ins (cdr (assoc 10 data))   ; get the insertionpoint of the block allready placed
      ; why not block_ins (cdr (assoc 10 entity)) ?
      ; Because of the entget thingy...
      ; I'll go to the Alisp manual I have to explore that.

block_scx (cdr (assoc 41 data))   ; get the scale in x direction of the block allready placed

block_scy (cdr (assoc 42 data))   ; get the scale in y direction of the block allready placed

block_rot (cdr (assoc 50 data))   ; get the rotation of the block allready placed
      ; I believe I have to turn this in to degrees (?)

block_rot_dgr (/ (* block_rot 180.0) pi) ; Like this.

); end of the setq

; I have the info I need from the existing block.
; Now set the new insertion point, called pt1

(setq dist (Getdist "\nDistance?:"); Get distance by prompt

; this is where I mess things up:

; pt1 (polar block_ins (+ block_rot_dgr (* 0.5 pi)) dist); ==> does not work
; pt1 (polar block_ins (* 0.5 pi) dist); no good either...
pt1 (polar block_ins (* 1 pi) dist); no good either...

; AArrgghh - HOw to get that point ??

); end of the setq

(setvar "osmode" 0); just to turn off quickly for command function

(command "_.insert" "w1" pt1 block_scx block_scy block_rot_dgr)

(princ)

); end of function


MarcoW 发表于 2022-7-6 12:49:43

我有一个自己的派对。。。
 
pt1 (polar block_ins (+ block_rot (* 0.5 pi)) dist)
 
... 就是这样。。。

MarcoW 发表于 2022-7-6 12:50:48

这就是我想到的。
 

;;; Addblock.lsp by MarcoW on CadTutor
;;; Written 21-12-2009
;;; To place a block next to another with same rotation and scaling
;;;
;;; Any improvements or comments are more than welcome!
(defun c:addblock (/      newblock    entity      data
    block_ins   block_scx   block_scy   block_rot
    block_rot_dgr    dist      pt1
    pt2      oldosmode   side
   )
(setq newblock      (cdr (assoc 2 (entget (car (entsel "\nSelect object to place (new block): " )))))
entity       (car (entsel "\nSelect an allready placed block:"))
data       (entget entity)
block_ins   (cdr (assoc 10 data))
block_scx   (cdr (assoc 41 data))
block_scy   (cdr (assoc 42 data))
block_rot   (cdr (assoc 50 data))
block_rot_dgr (/ (* block_rot 180.0) pi)
dist       (getdist "\nDistance?: ")
pt1       (polar block_ins (+ block_rot (* 0.5 pi)) dist)
pt2       (polar block_ins (+ block_rot (* 1.5 pi)) dist)
oldosmode   (getvar "osmode")
)
(setvar "osmode" 0)
(initget "L R")
(setq
   side (getkword
   "\nOn wich side do you want the new block? (L/R) <R>:"
)
)
(cond
   ((= side "L")
    (command "_.insert" newblock pt2 block_scx block_scy block_rot_dgr)
   )   ;
   (t
    (command "_.insert" newblock pt1 block_scx block_scy block_rot_dgr)
   )
)
(setvar "osmode" oldosmode)
(princ)
)


 
目前:问题已解决。

David Bethel 发表于 2022-7-6 13:00:27

为什么不复制一下呢-大卫
页: [1]
查看完整版本: 计算新i的问题