Jump to content

Create associative path array with an inserted block


Recommended Posts

Posted (edited)

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.b6622f5740bb6e220f64191bddb4bc6c.JPG

 

Example of Associated path array using inserted block when successful:

MyArraypath.thumb.JPG.f9f2bda686702341e6a7b03f9f3c8e8e.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!

MyArray_block.dwg

Edited by RLispLearner
Adding more information
Posted

Did you do another post about using patharray somewhere remember seeing it ? Ok 1st suggestion give up on path array much easier to just use a repeat in a lisp and insert the block aligning along a pline. Thats the way I would do it.

 

You need to post a dwg with real p/line work so can see length of line segments etc. What happens if line length is not a factor of 4 ?

Posted

Thanks for your quick reply! I posted a Dwg with this post. Hopefully you can download it and see the block. Also, it needs to be an associative path array because there is a 95% chance it needs to be altered once created by the user. Pulling on the  grip handles of the associated array allows that change as blocks are either added or reduced when adjusting the line. The path draw is just an initial starting point for the user and then it need to be fine tuned once the array is created. At my office we are doing things manually and it is tedious so looking for a better solution...🙂

Posted

I went ahead and added a DWG file of a random polyline for testing. There should already be a DWG of the block mentioned above.

 

Please Note: The Polyline will have an unknown length because it will be base on a projects specific parameters and every project is different. A line is created to be a close proximity.  Once the Array is created, pulling the grip handles will allow the blocks to fit properly for the length needed as they will be added or removed when adjusted.

Please see attached DWG of a random polyline for testing.

 

Thanks BigAl for your input...!

Random_polyline_for_Array.dwg

Posted (edited)

Ok BIG STEP 1 the insertion point is at wrong point. should be at center of link etc. I will fix for testing. I am still confused what happens if segment length is not 4'. 

 

Is it like this for a solution. A contious repeat of the block correctly aligned 

Forklift.thumb.png.bf7075efaf5a3d301cbb907f1c64b87d.png

 

Is this what happens at change of direction as per forklift image. It was set to 1.5m spacing. I have that code done.

 

Almost there does not use array path. Couple of bugs to fix. Note the vertex point block end i on next segment.

image.thumb.png.f7f2ff6986c0f8464487207a76f25e31.png

Edited by BIGAL
Posted

Thanks BigAl for all your hard work.

 

The blocks wont fit the line most likely the first time. The blocks will be going around a shape and the blocks need to be close to that shape. Shape is based on  the specific project and can change.  Each shape different for each project. The two ends of the line will be "hooked" into another object to complete a "loop" so the blocks need to be adjusted to stop at the end points, but in-between the adjustments can be made to both be as close to the shape in the center but also fit the 4' segments. Like a chain.  Right now, my team is doing this manually and when there are changes to the shape its surrounding, more adjustments are needed. Takes time.  I think if its associative, that would cut down allot of work. More Vertex points will most likely need to be created so grab handles can be "snapped" to the 4' segments but that would be quicker than manually adjusting. . The horseshoe  shape in my drawing is somewhat typical for a project. I would first make my poly line go around the shape and  "hook" into an object on both ends to complete the loop. Next do the array and then adjust the line to fit the segments. It will also make updates quicker if there are changes to the shape...Trying to take something tedious and hopefully make it easier. Thanks again! 🙂

Posted (edited)

Please post a completed dwg still struggling to understand what you want, provide a couple of examples. Show steps in getting to final answer.

 

" Like a chain." that is what I did. 

Edited by BIGAL
Posted

Thanks for your help. I will work on posting a mock up dwg with steps included....🙂

Posted

Hi BigAl. Sorry for the late reply.  I am attaching a typical project showing the before and after of what I create manually. I have to closely surround shapes with the 4' overlapping block that I have and loop them around (like a chain). This drawing is just the basics of the project so I only left the essentials, which are the shapes (before and after completion). On this actual project the design did end up changing and the blocks had to be adjusted to fit the new parameters. This is typical so I thought it would make a good example to show.  But I am now thinking of a more efficient way. My "chain" will always be these 4' overlapping blocks on every project. As of now, I am manually copying and rotating them into place and surrounding the objects. I found some code where someone set a specific length for the polyline segments. Perhaps I can forgo having the user either choose or create the polyline and just have them create one regardless, but limited to the four foot (4') segments when drawing the loop. That would cut down on the adjustments after. Although its a low probability of getting the 4' segments perfect for the entire loop on the first run, it can just be the end that needs adjustment. That would save time... I will have to look for that code again. My goal is to execute the routine. User is then prompted to draw a polygon loop around the shapes. Then the block is automatically inserted from a file, placed at the beginning of the line, rotated to align with the polyline and then arrayed at 4' intervals. After its done, adjust as needed to complete the loop. Then in the future if the shapes change, I only need to adjust the array without having to start over. See attached for the DWG. Again, thanks for your input! If there is a more efficient way to accomplish this, please let me know. I am open to all ideas! Thanks BigAl!

 

Project_Example.thumb.JPG.7fa043d74e7b4e8c652aeae22306546c.JPG

Project_Example.dwg

Posted

Ok a 2step process draw a dummy line with 4' or some other measurement increments so a line segment is like 5x4 4x4 as you draw lines around the shape. The only issue is the closing end segment has to be worked out via intersection of two circles. You would just pick points with a dummy line displayed via "(setq pt2 (getpoint pt1" then it is overdrawn as 4' increments. So that is 1st task to make work, adding blocks is easy part. 

 

image.png.65d8301ac814a10b4000915a5f9b304b.png

 

Added to my to do list. 

Posted

Thanks BigAl for all your input and hard work. I did throw my question out to various other forums and got some interesting solutions back. The array is turning out difficult as you stated. It has to be adjusted and its unpredictable sometimes when executed. it can have ugly results. A forum member named BeekeeCZ gave an alternate to using an array. Letting the user draw lines at 48" increments then joining the lines into one. He then had another routine that put the block along the lines path. Both work great. I combined both routines into one and it works. See link below for conversation. 

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/create-associative-path-array-with-an-inserted-block/td-p/13171401#M475246

 

Some array code was also given in the forum and I tried it out but I sometimes get strange results so I will have to keep work on that. My last task is to find code that will bring in my block into a drawing so I can add that code for an "all in one solution". Thanks again for all your help. Its very much appreciated!

 

 

Posted

Just as simple as, just need poly saved as a dwg use wblock.

(command "-insert" "poly" "0,0" 1 1 0)
(command "erase" (entlast) "")
(command "purge" "Block" "poly" "y") ; this was a guess will be close.

 

Posted

Thanks! I think this was the reason my routine wouldn't even run. I think it kept failing at this point when trying to insert the block.
My code:

(command "_insert" "C:\\Users\\B\\Desktop\\MyArray_block.dwg" insertpt1 "" "" "")

(setq myarrayblock (ssget "L" ))

 

Do you know the proper way of adding an external path? I just had it saved to my desktop for testing...

Can you describe this part of your insert command? I just took the defaults...

1 1 0)

Thanks!

Posted

Scale x, Scale Y, Rotation.

 

Look at what I posted carefully "-insert".

Posted

Got it. Working now...Thanks BigAl!

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...