how to insert block along with UCS?

how to insert block along with UCS?

thsa2501
Enthusiast Enthusiast
1,496 Views
13 Replies
Message 1 of 14

how to insert block along with UCS?

thsa2501
Enthusiast
Enthusiast

hii Everyone

i want to insert a block along with UCS with the below AutoLISP.i don't know what are function to insert in this code. kindly help me.

i attached two dwg one is a sample drawing,2nd one is a block drawing.

(defun c:try()
(getvar "osmode")
(setvar "osmode" 0)
(setq a (ssget '((0 . "insert"))))
(setq slen (sslength a))
(setq i 0)
(setq scl (getreal "\nEnter the scale<none>:"))
(repeat slen
   (setq b (entget (ssname a i)))
  (setq c  (cdr (assoc 10 b)))
  (setq c (trans c 1 0))
  (vl-cmdf "insert" "coor.dwg" c 1 0  "" "" "" "")
  (vl-cmdf "scale" c "" c scl )
  (setq i (1+ i))

)
(setvar "osmode" 512)
)

 

 

0 Likes
Accepted solutions (2)
1,497 Views
13 Replies
Replies (13)
Message 2 of 14

ВeekeeCZ
Consultant
Consultant

This transition should be the other way around.

 (setq c (trans c 1 0))

 

While entdef stores the coords in WCS, the INSERT command needs them in UCS.

Message 3 of 14

thsa2501
Enthusiast
Enthusiast

hii,

i did not understand what are you trying to say. don't mind pls

did you open my drawing? if not pls open the lighting drawing, you will understand what i am trying to say.

0 Likes
Message 4 of 14

ВeekeeCZ
Consultant
Consultant

As a matter of fact, I did. But I did not understand what the issue was.

Need a smaller sample... and clearly see what gets wrong and what is your desired result.

Message 5 of 14

thsa2501
Enthusiast
Enthusiast

hi,

the plan if inclined.when i select a block using this code.the result is the horizontal way.i don't want this way

my desired result which is shown image below.i hope u will understand everything.

thanks advance

 

 

sample.JPG

Message 6 of 14

ВeekeeCZ
Consultant
Consultant
Accepted solution

See if this moves you a little forward.

 

 

(defun c:try( / osm s a i scl rot slen )
  (setq osm (getvar "osmode"))
  (setvar "osmode" 0)
  (setq s (ssget '((0 . "insert"))))
  (setq slen (sslength s))
  (setq i 0)
  (setq scl (cond ((getreal "\nEnter the scale <1>: ")) (1)))
  (setq rot (cond ((getangle  "\nEnter additional rotation angle <0>: ")) (0 )))
  (repeat slen
    (setq b (entget (ssname s i)))
    (setq a (cdr (assoc 50 b)))
    (setq c (cdr (assoc 10 b)))
    (setq c (trans c 1 0))
    (vl-cmdf "insert" "coor.dwg" "_s" scl "_r" (angtos (+ a rot) (getvar 'aunits) 6) "_non" c)
    (setq i (1+ i)))
  (setvar "osmode" osm)
  )

 

Message 7 of 14

thsa2501
Enthusiast
Enthusiast

hi,

thank you so much for your reply. it works for one block, not a continuous block.

kindly see the image. this is I got while using your modification of code for the continuous block.i have another issue i did not get  coordinate for a continuous block.

 

sample.JPG

0 Likes
Message 8 of 14

ВeekeeCZ
Consultant
Consultant

I probably don't understand your image. IMHO it works flawlessly.

It inserts a label block at an angle in relation to the rotation of the labeled block.

 

But it really does not matter. Not here to make adjustments here and there. Just showed you some way, it's up to you to adjust minor nuances according to your needs. You need to learn yourselves.

Take it or leave it. Good luck!

0 Likes
Message 9 of 14

thsa2501
Enthusiast
Enthusiast

hi

thank you so much creating the code for me and appreciate your effort.

Best Regards

Hussain

0 Likes
Message 10 of 14

komondormrex
Mentor
Mentor
Accepted solution

hi,

the routine will place "coor" block to insertion points of selected unidirectional "lights with poll" blocks. scale of initially placed "lights with poll" block will be remembered till it nilled with (setq block_scale nil). rotation to "coor" block should be defined to every unidirectional selection of  "lights with poll" blocks.

 

(defun c:place_blocks (/ index ignore_empty_sset block_sset block_name block_rotate)
	(vla-startundomark (vla-get-activedocument (vlax-get-acad-object)))
	(repeat (sslength (setq index -1
							ignore_empty_sset (while (null (setq block_sset (vl-catch-all-apply 'ssget (list "_:L" '((0 . "insert") (2 . "lights with poll")))))))
							block_sset (cond
											(
												(vl-catch-all-error-p block_sset)
													(princ "\nCommand cancelled")
													(ssadd)
											)
											(
												t
													block_sset
											)
									   )
					  )
			)
			(setq target_block_insert_point (cdr (assoc 10 (entget (ssname block_sset (setq index (1+ index)))))))
			(if (null block_name)
					(progn
						(command-s "_-insert" (setq block_name "coor") target_block_insert_point "" "" "")
						(if block_scale (command-s "_scale" (entlast) "" target_block_insert_point block_effectivescale))
						(command-s "_rotate" (entlast) "" target_block_insert_point)
						(if (null block_scale)
							(progn
								(command-s "_scale" (entlast) "" target_block_insert_point)
								(setq block_scale (vla-get-xscalefactor (vlax-ename->vla-object (entlast)))
									  block_effectivescale (vla-get-xeffectivescalefactor (vlax-ename->vla-object (entlast)))
								)

							)
						)
						(setq block_rotate (vla-get-rotation (vlax-ename->vla-object (entlast))))
					)
					(vla-insertblock (vla-get-block (vla-get-activelayout (vla-get-activedocument (vlax-get-acad-object))))
							 		 (vlax-3d-point (trans target_block_insert_point 1 0))
							 		 block_name
							 		 block_scale
							 		 block_scale
							 		 block_scale
							 		 block_rotate
					)
			)
	)
	(vla-endundomark (vla-get-activedocument (vlax-get-acad-object)))
	(princ)
)

  

Message 11 of 14

thsa2501
Enthusiast
Enthusiast

hi,

thanks for the reply, i got an error message while using your code. I attach here an image for your information.

 

 

error message.PNG

0 Likes
Message 12 of 14

komondormrex
Mentor
Mentor

dunno, it is obviously points to the redefinition of the *error* function...

 

PB_1.gif

0 Likes
Message 13 of 14

thsa2501
Enthusiast
Enthusiast

hi,

i don't know what to do here. i checked completely. the same error message popup.

0 Likes
Message 14 of 14

komondormrex
Mentor
Mentor

try to reset *error* function with that (setq *error* nil)

0 Likes