Insert and align block

Insert and align block

sam_safinia
Advocate Advocate
1,220 Views
7 Replies
Message 1 of 8

Insert and align block

sam_safinia
Advocate
Advocate

I have this lisp to inser block but I want to align and associate the block with last inserted block.

and also roate the block 90 degree before insertion.

 

Spoiler
(defun c:test ( / e )
(if
(and
(setq e (car (entsel "\nSelect Block: ")))
(eq "INSERT" (cdr (assoc 0 (entget e))))
)
(command "_.insert" "Dtag" "_scale" 1 "_rotate" (angtos (cdr (assoc 50 (entget e)))) "" "" )
)
(princ)
)

Thanks

 

0 Likes
1,221 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

@s_plant wrote:

.... I want to align and associate the block with last inserted block. and also roate the block 90 degree before insertion.

 

Spoiler
....
(command "_.insert" "Dtag" "_scale" 1 "_rotate" (angtos (cdr (assoc 50 (entget e)))) "" "" )
...

I'm having a little trouble understanding the combination of "align ... with last inserted block, and ... rotate ... 90 degrees."  If you mean that you want to rotate it 90 degrees more than the rotation of the selected Block [align with it as a basis and rotate it 90 degrees further from there], then I think you need to change the line quoted above to this:

 

(command "_.insert" "Dtag" "_scale" 1 "_rotate" (angtos (+ (cdr (assoc 50 (entget e))) (/ pi 2))) pause)

 

The pause is for the User input of the insertion point, if that's what you mean.  The scale and rotate options used in the Insert command will cover those things, and they won't be asked for after the insertion point, so your Enters [""] are inappropriate.  If perhaps you want it Inserted at the selected Block's insertion point, replace the pause with

 

(cdr (assoc 10 (entget e)))

 

[You have enough extractions from the entity data list that it may be worth saving what (entget e) returns to a variable to use in place of all those repetitions of it.]

 

The (+ ... (/ pi 2)) will rotate it counterclockwise from the selected Block's rotation.  If you want to go the other way, use (- ... instead.

 

 

Kent Cooper, AIA
0 Likes
Message 3 of 8

sam_safinia
Advocate
Advocate

Kent,

 

Thanks for your reply and sorry for my bad explanation. This is what I want to do:

I have a lisp to insert a block (dynamic block) that actually are 2D pipe. After insertion each pipe block, I have another routine for insertion a tag for that piece of pipe. What I want to do is my tag block align itself with inserted block(pipe) during the process of insertion. The ideal scenario would be the tag insert on the edge of pipe block with specific offset distance from the edge at the insertion point.

 

Any idea for edge insertion with specific offset?

 

Also I noticed with my initial attempt that pipe block and tag block have 90 degree difference although both have got same rotation angle!

 

Thanks

 

 

0 Likes
Message 4 of 8

ВeekeeCZ
Consultant
Consultant

@s_plant wrote:

... What I want to do is my tag block align itself with inserted block(pipe) during the process of insertion. ...

 


Have you try adjust your tag block by adding an alignment parameter? See here Then all you need is to hover the cursor over...

0 Likes
Message 5 of 8

sam_safinia
Advocate
Advocate

Thanks for reply guys. Still have not solved my issue for the plan that I had...

I am thinking to other ways and it is working half-half and need to be revisited.

 

I got another idea from this post  but how can I handle the error and user get prompt of wrong selection(or non) until pick the right edge of the blockr:

 

Spoiler
.....
(setq
osm (getvar "osmode")
pt (getpoint "\nPick an edge: ")
ang (angle (osnap pt "_nea") (osnap pt "_end"))
)
.....

At  the moment by clicking other place on screen the routine is terminated and I get this error:


Error: bad argument type: 2D/3D point: nil

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant

@s_plant wrote:

 

....

I have a lisp to insert a block (dynamic block) that actually are 2D pipe. After insertion each pipe block, I have another routine for insertion a tag for that piece of pipe. What I want to do is my tag block align itself with inserted block(pipe) during the process of insertion. The ideal scenario would be the tag insert on the edge of pipe block with specific offset distance from the edge at the insertion point.

 

.... 

How about an ATTRIBUTE in the Block definition?  This is just the kind of thing they exist for.  It would mean the tag value would be asked for in the Insertion process, and the tag would always be aligned/positioned in the same way in relation to the pipe, without any separate routine, etc.

Kent Cooper, AIA
0 Likes
Message 7 of 8

sam_safinia
Advocate
Advocate
Actually my tag includes 4 texts that will be within a rectangular box. Two
of them are extracting from current layer
and also dblk property. The remaing two will be user input just before
adding to the pipe edge. I know about dblk attribute but comination of
these 4 texts plus free movment of my tag box(rectangular) along pipe route
was not easy to handle then I ended up of inserting seperaye entity to get
the job done.
It is working fine now but the only issue is it has no live information to
update if my block parameters change.

Thanks again.
0 Likes
Message 8 of 8

Kent1Cooper
Consultant
Consultant

@s_plant wrote:

.... 

I got another idea ... but how can I handle the error and user get prompt of wrong selection(or non) until pick the right edge of the blockr:

 

Spoiler
.....
(setq
....
pt (getpoint "\nPick an edge: ")
ang (angle (osnap pt "_nea") (osnap pt "_end"))
)
.....

At  the moment by clicking other place on screen the routine is terminated and I get this error:


Error: bad argument type: 2D/3D point: nil


You can handle that by doing something like this, relying on selecting an entity rather than a point, so that it can ask again if you missed:

 

....

(while (not esel)

  (setq esel (entsel "\nPick an edge: ")); returns nil if you don't hit something

); while

(setq

  pt (cadr esel)

  ang (angle (osnap pt "_nea") (osnap pt "_end"))

); setq

....

Kent Cooper, AIA
0 Likes