Almonan Posted October 25, 2021 Share Posted October 25, 2021 Hello Everyone, Is my first topic here at the forum. I'm still learning how to program in Autolisp so I can Automate parts of my daily workflow. At the moment Im having issues with this part of the code: (vl-load-com) (defun c:Si3_TRACKER (/ *error* poly minExt maxExt blname) ;; This example creates a line in model space. It then finds the ;; bounding box for the line and displays the corners of the box. (setq acadObj (vlax-get-acad-object)) (setq doc (vla-get-ActiveDocument acadObj)) (setq modelSpace (vla-get-PaperSpace doc)) ;; Select the polyline (setq poly (vlax-ename->vla-object (car (entsel)))) (vla-ZoomExtents acadObj) ;; Return the bounding box for the line and return the minimum ;; and maximum extents of the box in the minExt and maxExt variables. (vla-GetBoundingBox poly 'minExt 'maxExt) (setq minExt (vlax-safearray->list minExt) maxExt (vlax-safearray->list maxExt)) (setq BlockObj (vlax-ename->vla-object (car (entsel)))) (setq BlockName (LM:effectivename BlockObj)) (setq blockRefObj (vla-InsertBlock modelSpace ip BlockName 1.0 1.0 1.0 0.0)) ) The problem is that it doesn`t insert Anything, it reads the Polyline, gets the bounding box, then it reads the block I want to insert but the resut is nothing. What I'm doing wrong? I have used some code from Lee Mac so I could get the name of the Block to use it on the vla-InsertBlock. Thanks in advanced. Quote Link to comment Share on other sites More sharing options...
rlx Posted October 25, 2021 Share Posted October 25, 2021 what / where is IP? 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted October 25, 2021 Share Posted October 25, 2021 afralisp Example? Your using this to insert a title block or something in paper space? only ask because your using vla-get-PaperSpace with a variable ModelSpace. also you don't set a ip point like in the example. You could use one of the two bounding box points instead of ip. (defun c:Si3_TRACKER (/ blk blkname poly minExt maxExt) (vl-load-com) (setq blk (car (entsel "\nSelect Block: "))) (setq blkname (cdr (assoc 2 (entget blk)))) (setq poly (vlax-ename->vla-object (car (entsel "\nSelect Polyline")))) (vla-GetBoundingBox poly 'minExt 'maxExt) (setq minExt (vlax-safearray->list minExt) maxExt (vlax-safearray->list maxExt) ) (vl-cmdf "-Insert" blkname minExt "" "" "") (princ) ) you could also hard code the block either by the path. or if its already in the drawing use quotes around its "name" (vl-cmdf "-Insert" "c:\\blocks\\block1.dwg" minExt "" "" "") (vl-cmdf "-Insert" "block1" minExt "" "" "") (vl-cmdf "-Insert" "block1" pause "" "" "") add pause to let the user select insertion point. can eliminate selecting the polyline and getting the bounding box if all you want to do is select the bottom left of the poly. 1 Quote Link to comment Share on other sites More sharing options...
Almonan Posted October 26, 2021 Author Share Posted October 26, 2021 Hi again, Thank you both for the replies. 15 hours ago, rlx said: what / where is IP? About that, the thing is that IP means Insertion Point, and because I've changed a lot my code is possible that instead of using minExt as the Insertion Point I've put IP. Sorry for the confusion. 15 hours ago, mhupp said: afralisp Example? Your using this to insert a title block or something in paper space? only ask because your using vla-get-PaperSpace with a variable ModelSpace. also you don't set a ip point like in the example. You could use one of the two bounding box points instead of ip. (defun c:Si3_TRACKER (/ blk blkname poly minExt maxExt) (vl-load-com) (setq blk (car (entsel "\nSelect Block: "))) (setq blkname (cdr (assoc 2 (entget blk)))) (setq poly (vlax-ename->vla-object (car (entsel "\nSelect Polyline")))) (vla-GetBoundingBox poly 'minExt 'maxExt) (setq minExt (vlax-safearray->list minExt) maxExt (vlax-safearray->list maxExt) ) (vl-cmdf "-Insert" blkname minExt "" "" "") (princ) ) you could also hard code the block either by the path. or if its already in the drawing use quotes around its "name" (vl-cmdf "-Insert" "c:\\blocks\\block1.dwg" minExt "" "" "") (vl-cmdf "-Insert" "block1" minExt "" "" "") (vl-cmdf "-Insert" "block1" pause "" "" "") add pause to let the user select insertion point. can eliminate selecting the polyline and getting the bounding box if all you want to do is select the bottom left of the poly. Thank you for the help mhupp. The thing is that I thought that It was necessary to declare the variables for acad object, active document etc to make a functional scrip. (setq modelSpace (vla-get-PaperSpace doc)) Then I suppose that declaring "modelSpace" as the paper-Sapce of the doc I'm telling to the script to insert the block in the paper space instead of the model space. Am I right? To explain a little bit of what I'm trying to do: once the block is placed on the bottom left corner of the bounding box, i will create an array with an extent equal/similar to the bounding box and then explode the array and erase all the blocks that are not inside the polygon. I'm going to test your feedback and will reply if I have anything new. See you. Quote Link to comment Share on other sites More sharing options...
mhupp Posted October 26, 2021 Share Posted October 26, 2021 1 hour ago, Almonan said: The thing is that I thought that It was necessary to declare the variables for acad object, active document etc to make a functional scrip. Some visual lisp Commands need it (mostly placing/creating objects) but not all. and regular lisp commands don't. Then I suppose that declaring "modelSpace" as the paper-Sapce of the doc I'm telling to the script to insert the block in the paper space instead of the model space. Am I right? Yes, Im sure if you check any tabs you have other then model space. You will see a bunch of blocks pasted there. Make sure the insertion point of the block is also lower left. http://www.lee-mac.com/changeblockinsertion.html 1 Quote Link to comment Share on other sites More sharing options...
Almonan Posted October 26, 2021 Author Share Posted October 26, 2021 Hi Again, The problem is solved. Now I'm able to insert the block in the Model Space and then use it to make the array. And yes, I went to the Layout tab and it was full of blocks pasted on it . I would like to thank you again mhupp for your help. If i have ay more doubts I will write again on the forum. See you. 1 Quote Link to comment Share on other sites More sharing options...
mhupp Posted October 26, 2021 Share Posted October 26, 2021 Forgot about this might want to check it out. Uses a menu but its in french. maybe ask @Elektrik if he translated it. 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.