Qonfire Posted August 11, 2011 Share Posted August 11, 2011 Hello I need help i want to scale my block upon inesrtion here where i am (defun c:MyBlock (/ pt) (setq pt1 (getpoint "\nPick Insertion point.")) (setq pt2 (getpoint "\nPick Insertion point.")) (setq d (command "dist" pt1 pt2)) (command "-insert" "1" "_non" pt1 (nth 0 d) "" "") ////y scale depends on user input the rotation can wait (princ) ) its not working out,I would like to use it tomorrow thank you Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 11, 2011 Share Posted August 11, 2011 (edited) Quick rewrite with the code you posted: (defun c:MyBlock ( / pt1 pt2) (if (and (setq pt1 (getpoint "\nPick Insertion point.")) (not (initget 32)) (setq pt2 (getpoint pt1 "\nPick Insertion point."))) (command "._-insert" "1" "_non" pt1 (distance pt1 pt2) "" pause)) (princ)) ** A few alterations, and sysvar changes would clean this up nicely. Edited August 11, 2011 by BlackBox Quote Link to comment Share on other sites More sharing options...
pBe Posted August 11, 2011 Share Posted August 11, 2011 Are you pertaining to ration of X to Y wherein X is 1 and Y will depend on pick points? Not sure of your intentions but i'm inlcined to do it this way: (defun c:MyBlock (/ pt) (setq pt1 (getpoint "\nPick Insertion point.")) (setq pt2 (getpoint pt1 "\nPick Insertion point.")) (command "-insert" "1" "_non" pt1 1 (1+ (/ 1 (distance pt1 pt2))) "") (princ) ) EDIT: Oooops .. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2011 Share Posted August 11, 2011 Plus this for more insurance (tblsearch "BLOCK" "1") Quote Link to comment Share on other sites More sharing options...
pBe Posted August 11, 2011 Share Posted August 11, 2011 Plus this for more insurance (tblsearch "BLOCK" "1") Ah! good ol preventive measures. Yeah. why not, you can never be too sure Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 11, 2011 Share Posted August 11, 2011 If the block resides in SFSP, then there's no need for that. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2011 Share Posted August 11, 2011 If the block resides in SFSP, then there's no need for that. Hi, What's this SFSP ? Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 11, 2011 Share Posted August 11, 2011 SFSP = Support Files Search Paths I say there's no need for TBLSEARCH, as the block will either be inserted by Reference (TBLSEARCH = Non-nil), or that which is 'found' (FINDFILE ). Once inserted the first time, the reference is used in subsequent insertions. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2011 Share Posted August 11, 2011 That's right , But all routines which have been given shows that the block is being inserted from current drawing and not as external or so . Thanks . Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 11, 2011 Share Posted August 11, 2011 I'm not sure what you are trying to achieve with regards to the Scale, but this might be one way to structure the code: (defun c:test ( / block p1 p2 ) (setq block "1") (if (or (tblsearch "BLOCK" block) (setq block (findfile (strcat block ".dwg"))) ) (if (and (setq p1 (getpoint "\nSpecify Insertion Point: ")) (setq p2 (getpoint "\nNext Point: ")) ) (command "_.-insert" block "_S" (distance p1 p2) "_R" 0.0 "_non" p1) ) (princ "\nBlock not found.") ) (princ) ) Quote Link to comment Share on other sites More sharing options...
pBe Posted August 12, 2011 Share Posted August 12, 2011 (edited) I'm not sure what you are trying to achieve with regards to the Scale, but this might be one way to structure the code: .... (setq block "1") (if (or (tblsearch "BLOCK" block) (setq block (findfile (strcat block ".dwg"))) ).... i've said it before. "preventive measures" Speaking of error, i usually use the function (cond ((and ... ))) (defun c:Test (/ a b c) (cond ((and (setq a (car (entsel "\Select Line:"))) (setq b (eq (cdr (Assoc 0 (entget a))) "LINE")) (setq c (getint "\nEnter Number of Cars: ")) (setq d (getpoint "\nPick Point on screen: ")) (princ "\nDone All Three:") ))) (princ) ) but most of my guys would ask what am i doing wrong? it just stops after i did this or not did that! what did i missed? where is the error message?" so i came up with a _error_mesage routine (defun c:Test (/ a b c) [color=blue](defun _errorMsg (lst / NilVal)[/color] [color=blue] (while (eval (setq NilVal (car (car lst))))[/color] [color=blue] (setq lst (cdr lst)))[/color] [color=blue] (if lst[/color] [color=blue] (alert (cadr (assoc NilVal lst))))[/color] [color=blue] )[/color] (cond ((and (setq a (car (entsel "\Select Line:"))) (setq b (eq (cdr (Assoc 0 (entget a))) "LINE")) (setq c (getint "\nEnter Number of Cars: ")) (setq d (getpoint "\nPick Point on screen: ")) (princ "\nDone All Three:") ))) [color=blue](_errorMsg[/color] [color=blue] (list '(a "Failed to select Object")[/color] [color=blue] '(b "Not a Line Entity")[/color] [color=blue] '(c "Failed to Enter Number")[/color] [color=blue] '(d "Failed ot pick a point")[/color] [color=blue] ))[/color] (princ) ) I know this might sound strange, but how would you use vl-catch-all-apply in conjunction with getpoint for catching errors? Normally I use initget/if once i even used ggread I'm not really efficient with error handling functions, sometimes i use good 'ol (setq *Error* oldError) thingy. for the love of me i cant seem to grasp the idea behind vl-catch-apply / vl-catch-all-error-p Here's what i thought i would use vl- error trapping (vl-catch-all-error-p (vl-catch-all-apply 'cadr (setq fp (getpoint "\nPick point:")))) But it appears on both instances of picking a point and not picking a point the result is T, what gives? -an ounce of prevention is better than a pound of cure Edited August 12, 2011 by pBe Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 12, 2011 Share Posted August 12, 2011 so i came up with a _error_mesage routine A nice idea pBe Using vl-some you could shorten it somewhat to something like: (defun c:Test ( / _errormsg a b c d ) (defun _errormsg ( lst / x ) (if (setq x (vl-some '(lambda ( x ) (if (null (eval (car x))) (cadr x))) lst)) (alert x) ) ) (cond ( (and (setq a (car (entsel "\nSelect Line:"))) (setq b (eq (cdr (assoc 0 (entget a))) "LINE")) (setq c (getint "\nEnter Number of Cars: ")) (setq d (getpoint "\nPick Point on screen: ")) (princ "\nDone All Three:") ) ) ( t (_errormsg '( (a "Failed to select Object") (b "Not a Line Entity") (c "Failed to Enter Number") (d "Failed to pick a point") ) ) ) ) (princ) ) I know this might sound strange, but how would you use vl-catch-all-apply in conjunction with getpoint for catching errors? You could use something along the lines of the following expression: (if (vl-catch-all-error-p (setq result (vl-catch-all-apply '[i][color=red]<somefunction>[/color][/i] (list (getpoint "\nSpecify Point: ")) ) ) ) (print (vl-catch-all-error-message result)) (princ result) ) Where is a function that will error when supplied with a null point argument. However, in my opinion, I feel this is bad programming practice since you are waiting for something to fail as opposed to preventing the error in the first place. (vl-catch-all-error-p (vl-catch-all-apply 'cadr (setq fp (getpoint "\nPick point:")))) But it appears on both instances of picking a point and not picking a point the result is T, what gives? This will error everytime since the vl-catch-all-apply function takes the same arguments as the apply function. With the above code, you are passing the selected point (or nil) as the list of arguments, which is equivalent to: (apply 'cadr '(1 2 3)) == (cadr 1 2 3) Which will error. However, note that a vl-catch-all-apply construct is not required for the cadr function since (cadr nil) = (cadr '( )) = nil Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 12, 2011 Share Posted August 12, 2011 (defun c:Test (/ a b c) [color=black](defun _errorMsg (lst / NilVal) [/color] [color=black] (while (eval (setq NilVal (car (car lst)))) [/color] [color=black] (setq lst (cdr lst))) [/color] [color=black] (if lst [/color] [color=black] (alert (cadr (assoc NilVal lst)))) [/color] [color=black] ) (cond ((and (setq a (car (entsel "\Select Line:"))) (setq b (eq (cdr (Assoc 0 (entget a))) "LINE")) (setq c (getint "\nEnter Number of Cars: ")) (setq d (getpoint "\nPick Point on screen: ")) (princ "\nDone All Three:") ))) [/color][color=black](_errorMsg [/color] [color=black] (list '(a "Failed to select Object") [/color] [color=black] '(b "Not a Line Entity") [/color] [color=black] '(c "Failed to Enter Number") [/color] [color=black] '(d "Failed ot pick a point") [/color] [color=black] ))[/color] (princ) ) That's really a very clever idea pBe . I may use it in the near future , hope you do not mind. Can I ? Quote Link to comment Share on other sites More sharing options...
Qonfire Posted August 13, 2011 Author Share Posted August 13, 2011 (edited) (defun c:MyBlock ( / pt1 pt2) (if (and (setq pt1 (getpoint "\nPick Insertion point.")) /////whats does (if(and fucntion do here? (not (initget 32))/////////why initget 32 (setq pt2 (getpoint pt1 "\nPick Insertion point."))) (command "._-insert" "1" "_non" pt1 (distance pt1 pt2) "1" pause))//////"_non" whats is it not do? (princ)) Thank you guys.RenderMan I just had to add 1 as a y scale. Now by picking two points Autocad draws me a a hatch pipe.Thank you all. Please explain questions.I would take autolisp courses with pleasure, but I dont look for them hard enougth apparently. Edited August 13, 2011 by Qonfire Quote Link to comment Share on other sites More sharing options...
pBe Posted August 13, 2011 Share Posted August 13, 2011 A nice idea pBe Using vl-some you could shorten it somewhat to something like:... (defun c:Test ( / _errormsg a b c d ) (defun _errormsg .... (princ) ) Glad you like the idea, i leave the elegant side of coding to you.... One more routine for the Toolbox .....Where is a function that will error when supplied with a null point argument..... Thank you for the info Lee, i'll give it a go.... Quote Link to comment Share on other sites More sharing options...
pBe Posted August 13, 2011 Share Posted August 13, 2011 That's really a very clever idea pBe . I may use it in the near future , hope you do not mind. Can I ? Of course you can Tharwat... I dont mind at all.. Cheers Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 13, 2011 Share Posted August 13, 2011 Of course you can Tharwat... I dont mind at all.. Cheers Thank you Buddy . Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 13, 2011 Share Posted August 13, 2011 (defun c:MyBlock ( / pt1 pt2) (if (and (setq pt1 (getpoint "\nPick Insertion point.")) /////whats does (if(and fucntion do here? (not (initget 32))/////////why initget 32 (setq pt2 (getpoint pt1 "\nPick Insertion point."))) (command "._-insert" "1" "_non" pt1 (distance pt1 pt2) "1" pause))//////"_non" whats is it not do? (princ)) AND function: http://www.cadtutor.net/forum/showthread.php?61672-Block-Attributes&p=419102&viewfull=1#post419102 initget: See VLIDE Help Docs on initget, look up Bit code 32. _non = _none = Ignore all OSnaps for next point. Quote Link to comment Share on other sites More sharing options...
Qonfire Posted August 15, 2011 Author Share Posted August 15, 2011 Thank you for your time Quote Link to comment Share on other sites More sharing options...
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.