Jump to content

Recommended Posts

Posted

Hi,

 

I was hoping to LOAD a lsp file then call it via (c:runthislispfile) inside another routine to combine them in one.

 

Problem is, they prompt for a selection, so I thought this would work:

(command "_P")
(while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))

 

Is this possible? I'm pretty sure it is with the cmdactive trick.

 

See code below and comments where the problem lies:

(defun c:---BB (/) (progn (LOAD "3dwannab_ByBlock_Change_Entities") (C:BB)))

; Change all selected entities to ByBlock and layer 0 & more.

(defun c:BB ( / ss_1 )

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss_1 (last (ssgetfirst)))
	(if (not ss_1)
		(setq ss_1 (ssget '((0 . "~HATCH"))))
		)
	(if ss_1
		(progn

			(command "._chprop" "_non" ss_1 "" "_LA" "0" "")
			(command "._chprop" "_non" ss_1 "" "_LT" "BYBLOCK" "")
			(command "._chprop" "_non" ss_1 "" "_LTS" "1" "")
			(command "._chprop" "_non" ss_1 "" "_LW" "BYBLOCK" "")
			(command "._chprop" "_non" ss_1 "" "_TR" "BYBLOCK" "")
			(command "._chprop" "_non" ss_1 "" "_C" "BYBLOCK" "")

			;; How do I run the command for this lisp then select previous and run it automatically.
			;; Below doesn't work.
			;; This routine is for rounding off entities to the nearest 0.5mm.
			(prompt "\nRUN the F5 command also to round off to 0.5mm ?\n")
			(load "FX_Round_Numbers_0Point5")
			(progn
				(c:F5)
				(command "_P")
				(while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
				)

			;; How do I run the command for this lisp then select previous and run it automatically.
			;; Below doesn't work.
			;; This is the PSIMPLE command to fix polylines. Again it prompts for a selection here.
			(prompt "\nRUN the PSIMPLE command also ?\n")
			(load "PSimple")
			(progn
				(c:PSIMPLEV) 
				(command "_P")
				(while (eq 1 (logand 1 (getvar 'CMDACTIVE))) (command ""))
				)

			(setq ss_1 nil)
			)
		(princ "\nUser Cancelled Command\n")
		)
	)

(*error* nil)
(princ)
)

(defun SS:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
	(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
	(princ (strcat "\n<< Error: " errmsg " >>\n"))
	)
(setvar 'cmdecho cmde)
(setvar 'osmode os)
(setvar 'orthomode orthom)
)

(defun SS:startundo ()
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
)

(vl-load-com)

(princ
(strcat
	"\n3dwannab_ByBlock_Change_Entities.lsp Loaded\n"
	"\nInvoke by typing 'BB'\n"
	)
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

Posted (edited)
Do you have the code for PSIMPLE? Does it work on preselected polylines? If so
(sssetfirst nil (ssget "P"))

should work.

 

another option: http://forums.augi.com/showthread.php?81175-select-result-lisp-modification#5

 

Sweet. I've needed this elsewhere. Thank you.

 

PSIMPLE's an amazing routine. Gets rid of those pesky non-closed polylines. As you can see I've called the verbose method which outputs the findings.

http://www.theswamp.org/index.php?topic=19865.msg244786#msg244786

 

Working code:

(defun c:---BB (/) (progn (LOAD "3dwannab_ByBlock_Change_Entities") (C:BB)))

; Change all selected entities to ByBlock and layer 0 & more.

(defun c:BB ( / ss_1 e i )

(setq *error* SS:error)
(SS:startundo)

(setq cmde (getvar "cmdecho"))
(setq os (getvar "osmode"))
(setq orthom (getvar "orthomode"))
(setvar 'cmdecho 0)
(setvar 'osmode 83)
(setvar 'orthomode 1)

(progn
	(setq ss_1 (last (ssgetfirst)))
	(if (not ss_1)
		(setq ss_1 (ssget '((0 . "~HATCH"))))
		)
	(if ss_1
		(progn

			(repeat (setq i (sslength ss_1))
				(setq i (1- i))
				(if (= "HATCH" (cdr(assoc 0 (ENTGET (setq e (ssname ss_1 i))))))
					(SSDEL e SS_1 ))
				)

			(command "._chprop" "_non" ss_1 "" "_LA" "0" "")
			(command "._chprop" "_non" ss_1 "" "_LT" "BYBLOCK" "")
			(command "._chprop" "_non" ss_1 "" "_LTS" "1" "")
			(command "._chprop" "_non" ss_1 "" "_LW" "BYBLOCK" "")
			(command "._chprop" "_non" ss_1 "" "_TR" "BYBLOCK" "")
			(command "._chprop" "_non" ss_1 "" "_C" "BYBLOCK" "")

			;; initget from LeeMac help pages
			(initget "Yes No")
			(setq ans
				(cond
					(
						(getkword
							(strcat "\nLoad FX_Round_Numbers_0Point5 and run ?\n: --------------------------------------------------------- :\nWill round off everything to the nearest 0.5\n: --------------------------------------------------------- :\n[Yes/No] <"
								(setq ans
									(cond ( ans ) ( "Yes" ))
									)
								">: "
								)
							)
						)
					( ans )
					)
				)

			(cond
				((=  "Yes" ans)
					(progn
						(prompt "\nNow running the 0.5mm round off command also...\n-------------------------------------\n")
						(load "FX_Round_Numbers_0Point5")
						(sssetfirst nil (ssget "_P"))
						(c:F5)
						)
					)
				((= "No" ans)
					(princ (strcat "\n: --------------------------------------------------------- :\nFX_Round_Numbers_0Point5.lsp not performed.\n: --------------------------------------------------------- :\n"))(princ)
					)
				)

			(repeat (setq i (sslength ss_1))
				(setq i (1- i))
				(if (/= "LWPOLYLINE" (cdr(assoc 0 (ENTGET (setq e (ssname ss_1 i))))))
					(SSDEL e SS_1 ))
				)

			(if (> (sslength SS_1) 0)
				(progn
					(prompt "\nNow running the PSIMPLEV command also...\n-------------------------------------\n")
					(load "PSimple")
					(sssetfirst nil (ssget "_P"))
					(c:PSIMPLEV)
					)
				(progn
					(princ (strcat "\nNo LWPOLYLINEs' found.\n: --------------------------------------------------------- :\n"))(princ)
					)
				)

			(setq ss_1 nil)
			(command "._regenall")
			)
		(princ "\nUser Cancelled Command\n")
		)
	)

(*error* nil)
(princ)
)

(defun SS:error (errmsg)
(and acDoc (vla-EndUndoMark acDoc))
(and errmsg
	(not (wcmatch (strcase errmsg) "*CANCEL*,*EXIT*"))
	(princ (strcat "\n<< Error: " errmsg " >>\n"))
	)
(setvar 'cmdecho cmde)
(setvar 'osmode os)
(setvar 'orthomode orthom)
)

(defun SS:startundo ()
(setq acDoc (vla-get-ActiveDocument (vlax-get-acad-object)))
(or (vla-EndUndoMark acDoc) (vla-StartUndoMark acDoc))
)

(vl-load-com)

(princ
(strcat
	"\n3dwannab_ByBlock_Change_Entities.lsp Loaded\n"
	"\nInvoke by typing 'BB'\n"
	)
)
(princ)

;;----------------------------------------------------------------------;;
;;                             End of File                              ;;
;;----------------------------------------------------------------------;;

Edited by 3dwannab
Added more to the code. An initget. And to filter HATCHES from the ssgetfirst. And to only run PSIMPLEV if LWPOLYLINES > 0.
Posted

Updated the code above. This will be a lifesaver when editing blocks. I seem to spend all my time in the block editor..!!!

 

And it's No, Nay, never,

No, nay never no more block editor.

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