MarcoW Posted December 19, 2009 Posted December 19, 2009 Ugh.. THis is my code: (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) ) THis is what shloud happen: in a drawing I have a block, the first or origin block. I wand another block beside it, either lleft or right from it on the same baseline. THe distance in between should be 150mm. Nothing difficult I guess but I keep up ending with this: Select a block: ; error: bad argument type: numberp: nil I would add the option (left / right) in there with initget / keyword but I don't even come that far. Can anyone kick me in the right direction? I do not need full lisp, just the explain how to do so. Thanks. Marco. Quote
David Bethel Posted December 19, 2009 Posted December 19, 2009 Shouldn't ent_data be data? -David Quote
MarcoW Posted December 21, 2009 Author Posted December 21, 2009 Shouldn't ent_data be data? -David Oops... yeah: I was real blind I guess. And what about this one? block_rot (cdr (assoc 42 ent_data)) block_rot (cdr (assoc 50 ent_data)) Twice the same variablename.... I am working on it now again... Tnx for the reply. Quote
MarcoW Posted December 21, 2009 Author Posted December 21, 2009 Not the most handy way to post but to ask "inline" it works great for me. ; 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 (setq entity (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 Quote
MarcoW Posted December 21, 2009 Author Posted December 21, 2009 I am having a party of my own... pt1 (polar block_ins (+ block_rot (* 0.5 pi)) dist) ... would be the way... Quote
MarcoW Posted December 21, 2009 Author Posted December 21, 2009 THis is what I come up with. ;;; 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) ) For now: problem solved. Quote
David Bethel Posted December 21, 2009 Posted December 21, 2009 Why not just copy the thing? -David Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.