Jump to content

this code is not working in zwcad


reda

Recommended Posts

hii,

kindly give a solution to why is not working in zwcad.this code copy from Autodesk forum.

(defun c:place_blocks (/ index ignore_empty_sset block_sset block_name block_rotate)
    (vl-load-com)
	(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 "insert" (setq block_name "coor") target_block_insert_point "" "" "")
						(if block_scale (command "_scale" (entlast) "" target_block_insert_point block_effectivescale))
						(command "rotate" (entlast) "" target_block_insert_point)
						(if (null block_scale)
							(progn
								(vl-cmdf "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)
)

 

Link to comment
Share on other sites

apart from it being awful to read... can you edit the code above to replace the tabbed indentations with perhaps a space for each?

 

 

What does zwcad say / report when this doesn't work? what is the error  - just gives us some clue where to look for a solution....

  • Agree 1
Link to comment
Share on other sites

At a glance looks like something got uncommitted maybe and the naming convention makes me think this came from ChatGPT?

 

--Edit

 

This code is a HOT MESS

 

  • ssget doesn't need error handling. it either finds something or it doesn't.  wont throw an error if it doesn't find anything.
  • Also why are you making a selection set of the block you want to insert? (tblsearch "BLOCK" "blockname") would let you know if its in the drawing.
  • block_name is set after the if statement checking for it. and will be reset after lisp is "done" running so "true" side of this if will never run.
  • the true side of the if statement immediately overwrites the block_name so if it was set its always going to be "coor"
  • (command "rotate" (entlast) "" target_block_insert_point) stops just shy of a complete command (missing the rotation angle)

  • this would leave and open command in the prompt.

  • so when scale is inputted it will error

  • the vla-insertblock will never work since block_name, block_scale, and block_rotate will never set since the if statement will always be false. (all are set on the side of true)

 

It got the start and end undo points right tho!

 

You would be better off telling us what you want to do or even better yet upload a sample drawing. so we can start from scratch.

Edited by mhupp
  • Like 1
Link to comment
Share on other sites

On 2/9/2023 at 8:32 PM, Steven P said:

apart from it being awful to read... can you edit the code above to replace the tabbed indentations with perhaps a space for each?

 

 

What does zwcad say / report when this doesn't work? what is the error  - just gives us some clue where to look for a solution....

hii,

thanks for the reply. sorry for not correctly putting the code. i kept it again.I hopefully understand everything.

1. zwcad means the same as Autocad

2. when i tried to debug this code for zwcad in vs code. itself telling undefined function (command-s).

3. Actually, what i need here is the block want to insert along the drawing. I attached a sample drawing to understand more.

(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)
		(setq ignore_empty_sset (while (null (setq block_sset (vl-catch-all-apply 'ssget (list "_:L" '((0 . "insert") (2 . "lights with poll"))))))))
		(setq 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)
)

 

20SWCG00049-1-145-00-0000-0T0-05-000006 Fence Lighting Layout.dwg

Link to comment
Share on other sites

On 2/9/2023 at 11:03 PM, mhupp said:

At a glance looks like something got uncommitted maybe and the naming convention makes me think this came from ChatGPT?

 

--Edit

 

This code is a HOT MESS

 

  • ssget doesn't need error handling. it either finds something or it doesn't.  wont throw an error if it doesn't find anything.
  • Also why are you making a selection set of the block you want to insert? (tblsearch "BLOCK" "blockname") would let you know if its in the drawing.
  • block_name is set after the if statement checking for it. and will be reset after lisp is "done" running so "true" side of this if will never run.
  • the true side of the if statement immediately overwrites the block_name so if it was set its always going to be "coor"
  • (command "rotate" (entlast) "" target_block_insert_point) stops just shy of a complete command (missing the rotation angle)

  • this would leave and open command in the prompt.

  • so when scale is inputted it will error

  • the vla-insertblock will never work since block_name, block_scale, and block_rotate will never set since the if statement will always be false. (all are set on the side of true)

 

It got the start and end undo points right tho!

 

You would be better off telling us what you want to do or even better yet upload a sample drawing. so we can start from scratch.

hii,

thanks for the reply. I'm sorry that i kept the code that way.the next time I will correct it.

Link to comment
Share on other sites

On 2/9/2023 at 8:32 PM, Steven P said:

apart from it being awful to read... can you edit the code above to replace the tabbed indentations with perhaps a space for each?

 

 

What does zwcad say / report when this doesn't work? what is the error  - just gives us some clue where to look for a solution....

for more information kindly read https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-insert-block-along-with-ucs/m-p/11736021#M443412 this is working for autocad.

Link to comment
Share on other sites

If Command-s is the problem, try editing the code to remove the -s part, leaving just command - it should be happy with that though there might be other errors and problems like MHUPP said.

 

For your drawing would a polar array do the same thing?

Link to comment
Share on other sites

On 2/14/2023 at 3:28 PM, Steven P said:

If Command-s is the problem, try editing the code to remove the -s part, leaving just command - it should be happy with that though there might be other errors and problems like MHUPP said.

 

For your drawing would a polar array do the same thing?

Thanks for the reply,i already tried that one (command-s) but still not working in zwcad.is the polar array working only for circles?yes

Link to comment
Share on other sites

I don't know zwcad really but assuming that all the CAD software does similar things, their array functions, including polar array, should let you do them with all object

Link to comment
Share on other sites

33 minutes ago, Steven P said:

I don't know zwcad really but assuming that all the CAD software does similar things, their array functions, including polar array, should let you do them with all object

Ok,thank you so much

Link to comment
Share on other sites

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