Lisp placing certain amount of blocks by predetermined value

Lisp placing certain amount of blocks by predetermined value

Anonymous
Not applicable
552 Views
6 Replies
Message 1 of 7

Lisp placing certain amount of blocks by predetermined value

Anonymous
Not applicable

Hi all,

 

i'm working on a small lisp routine that places an certain amount of blocks (wtk) at a set distance between eachother.

I had in the past did this before but it;s sooo long ago that i forgot how to haha.

So if any of you could point me in the right direction that would be great.

 

What i was thinking was to add a loop with an increment at the end to end up with the amount as the predetermined "wtk" amount.

then also with each increment amount add 100 to the distance "DisT" so the next block will be placed 100 apart.

But i forgot where to add the increment and how to add 100 to the distance.

 

Thanks in advance.

 

 

  		(setq wtk (GetCell "B2"))
		(setq DisT 0.0)
(setq wtkD 0) (while wtkD < wtk (command "insert" "Silo Schoonwater" DisT 1 1 0 ) (setq DisT +(100.0)
(setq wtkD + 1) );end while
0 Likes
Accepted solutions (1)
553 Views
6 Replies
Replies (6)
Message 2 of 7

3wood
Advisor
Advisor

I would suggest to use ARRAY instead of any lisp routine.

Nowadays ARRAY is so smart that you can control the distance between each item and also change number of rows / columns by simply drag the grip point.

 

0 Likes
Message 3 of 7

Anonymous
Not applicable
3 wood. Yeah that would work if it's only that. But this is part of an bigger routine that does more then just that. So I can't really use array.
0 Likes
Message 4 of 7

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

.... 

What i was thinking was to add a loop with an increment at the end to end up with the amount as the predetermined "wtk" amount.

then also with each increment amount add 100 to the distance "DisT" so the next block will be placed 100 apart. ....


 

Function names first, arguments follow.  And the insertion point needs to be a point [one way of getting that is shown], not a raw distance.

 

Something like this [untested]:

 

(setq wtk (GetCell "B2"))
(setq DisT 0.0)
(setq wtkD 0)
(while (< wtkD wtk)
  (command "insert" "Silo Schoonwater" (vlax-curve-getPointAtDist yourpathentityname DisT) 1 1 0 )
  (setq DisT (+ DisT 100.0))

  (setq wtkD (1+ wtkD))
);end while

 

You may need:
(vl-load-com)

loaded first, and should either turn Object Snap off [if not already part of the larger routine] or use "_none" Osnap before the insertion point.

Kent Cooper, AIA
0 Likes
Message 5 of 7

Anonymous
Not applicable

Thanks Kent,

 

I've been working with the code, but i can't seem to get it to work with the vlax command.

Could you explain what entity path it's looking for, i tried to just enter the block name tried it with blockObj and block-obj.

but i keep getting errors.

 

 

0 Likes
Message 6 of 7

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... 

I've been working with the code, but i can't seem to get it to work with the vlax command.

Could you explain what entity path it's looking for, i tried to just enter the block name tried it with blockObj and block-obj.

but i keep getting errors.

 

 


I was thinking in terms of ["...one way of getting..."] points at distances along an object, such as a Line/Polyline/Arc/Spline/etc.  In that kind usage, you would need to have put an object's entity name into a variable.

 

If you're talking about placing them independent of any existing object, the insertion point still needs to be a point, not just a raw distance.  And the changes in distance need to be in some direction from somewhere.  One way to do that would be to establish an initial point to start from, and a direction to head in:

 

(setq

  wtk (GetCell "B2")
  DisT 0.0
  wtkD 0

  start (getpoint "\nInsertion point for first Block: ")

  dir (getangle "\nDirection to subsequent insertions: ")

)
(while (< wtkD wtk)
  (command "insert" "Silo Schoonwater" "_none" (polar start dir DisT) 1 1 0 )
  (setq DisT (+ DisT 100.0))

  (setq wtkD (1+ wtkD))
);end while

 

Such a thing could be made to offer an initial default direction [such as 0 degrees], etc.

Kent Cooper, AIA
0 Likes
Message 7 of 7

Anonymous
Not applicable

Thanks alot Kent,

 

Figured it out with that. i'll remember this one for sure. 

 

 

 

 

0 Likes