Create associative path array with an inserted block

Create associative path array with an inserted block

rebPTFNF
Contributor Contributor
2,491 Views
22 Replies
Message 1 of 23

Create associative path array with an inserted block

rebPTFNF
Contributor
Contributor

Hi all,

Trying to create a routine for a Path Array but routine wont even load to test. Looking for some help...

 

Goal:

Create an associative Path Array using a block from an inserted drawing (MyArray_block.dwg).

NOTE: I just have the drawing saved on my desktop so the path will need updating to match your address bar if you test it. Also,  I created a DWG file with a random polyline for testing called (Random_polyline_for_Array.dwg).

 

Steps:

-User either selects an existing Poly line OR creates a new one for the block to be arrayed to. The line will be based on the parameters of the given project so the length will not be know. Therefor the array must be adjustable.

-A drawing containing a block is then inserted and the block is then aligned to the Array Poly line at the start point.

-An associative array is created using the block at a distance of 4 feet apart. blocks will overlap. Length will be unknown which is why it needs to be associative. It can then be adjusted using the grip handle until it fits the project parameters.

 

Please see illustrations attached:

My block:

MyArrayblock.JPG

 

Example of a successful Path Array using this block and a random Polyline:

MyArraypath.JPG

 

My Code:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;; User selects or creates Associative path array using an inserted block;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun C:myarray (/ ln_sel arrayline StartPoint insertpt1 myarrayblock myangle mydistance blksecpoint);;
(vl-load-com)

(setq oldLUNITS (getvar "LUNITS"))

;Set Units to Architectural.
  (setvar "LUNITS" 4)
;Say YES to Polyine edits automatically.
   (setvar "PEDITACCEPT" 1)


;Tell user to select an existing polyline or create a new polyline
(princ "\nSelect an existing Polyline or create a new one: ");command prompt

;User selects existing polyline or draws a new polyline for Associative Path Array. Next, Get start point of that Polyline.

(setq ln_sel (car(entsel "\n Select a polyline:")))

(if (= (cdr(assoc 0 element)) "POLYLINE")
  (progn
    (setq arrayline (vlax-ename->vla-object (car ln_sel )));User saves Polyline
    (setq StartPoint (vlax-curve-getStartPoint arrayline ));save start point
  );Else
(command "_pline" pause); If no poyline selected, User draws a polyline
(setq ln_sel (entget "L" ));save Polyline user either selected or creates
(setq StartPoint (vlax-curve-getStartPoint arrayline )); save start point of array path Polyline
  );end progn
);end IF


;NEXT

;Insert block from a drawing. Insertion point same location as startpoint of the Associative Path Array Polyline
(setq insertpt1 StartPoint)
(command "_insert" "C:\\Users\\B\\Desktop\\MyArray_block.dwg" insertpt1 "" "" "");Insert drawing (saved on desktop for testing purposes)

(setq myarrayblock (ssget "L" )); save the block that was just inserted into drawing

;Preset my second point variables for my inserted block. Picking opposite end
(setq myangle (atoi "90")); Angle = 90 degrees from start point
(setq mydistance (atoi "48")); Distance =  48" (4') from start point

;Make the second known point on block 48 inches at 90 degrees from insert (or start) point
(setq blksecpoint (polar insertpt1 (angle myangle) mydistance)); point one is insertion or start point. Point two is 48" at 90 degree angle

;Now align the block

;Align the block to the Path Array using set points on block
  (if (and (setq blkp1 StartPoint);block insertion point
           (setq blkp3 blksecpoint); second point on block. 48" distance at 90 angle.
       (setq blkent myarrayblock);inserted block
       (setq blkp2 StartPoint); Second alignment point is same as start point (or rotation point)
       (setq blkp4 (osnap (cadr blkent) "_nea")); snap second block point somewhere on array path polyline
       )
    (command "_.align" blkent "" "_non" blkp1 "_non" blkp2 "_non" blkp3 "_non" blkp4 "" "_No")
  );End if


;Next, Path Array


;Next do an associative path array using the inserted block that has been aligned
(command "arraypath" blkent "" ln_sel "as" "yes" "items" mydistance "" "");; pick Block. Pick line. Distance 48" (4')


;Last, delete the insert block from the drawing
(if (/= blkent nil)(command "erase" blkent ""))

(setvar "LUNITS" oldLUNITS)

);end

Any assistance or suggestions are greatly appreciated!!!

Thanks all

0 Likes
2,492 Views
22 Replies
Replies (22)
Message 21 of 23

Sea-Haven
Mentor
Mentor
Accepted solution

I redid the myblock some 300 K its now 25k just redid wblock. Removed the proxy stuff. Renamed the dwg to POLY-4 in case you make other sizes.

 

You only need something like this. The reason you delete it is that you may not want it at "0,0" but it still exists as a block in your current dwg so can use normal insert or a lisp insert. Ps no need for Steal.

(command "-insert" "POLY-4" "0,0" 1 1 0)
(command "erase" (entlast) "")

 

Yes we had lots of block dwgs a lot with very little in them saved in a Blocks directory.

0 Likes
Message 22 of 23

rebPTFNF
Contributor
Contributor

Sorry for the late reply.  Back in town and just now catching up on your suggestions. So If I insert Poly-4.dwg that has myblock as a wblock, then immediately delete myblock from the drawing using entlast, the wblock still exists in the drawing and the routine can then use it (as if its still there at 0,0). I may have misunderstood so making sure I got it. Will try it out and hopefully I can get it to work for me.

Thanks!

0 Likes
Message 23 of 23

ВeekeeCZ
Consultant
Consultant

Well, you need to learn the concept of how blocks work in AutoCAD. What is a Block Definition, what is a Block Reference, what is a WBLOCK, when it's necessary to use it and when not... When you can PURGE a "block", what happens if you just delete a block from the drawing.... and so on. 

 

You are asking for unnecessary complicated solutions (over and over again) just because you don't understand the basics. 

0 Likes