selection set issue?

selection set issue?

zph
Collaborator Collaborator
1,005 Views
4 Replies
Message 1 of 5

selection set issue?

zph
Collaborator
Collaborator

Good day all,

I attempting to use the built in PEDIT command within AutoLISP.

I've included a sample drawing for the routine to execute on.

My routine chokes when in encounters the PEDIT command call.

Please, see below:

;;;;;-----=====     subFunction:  TESTY_joinLines     =====-----;;;;;
;;; Purpose: Where applicable, join lines together to become polylines.

(defun TESTY_joinLines ( / cntr peName peType fuzzD ssSeco ssPneu ssElec ssProc)
;(princ "\n a ")

(setq cntr 0)
(setq fuzzD 0.05)
(setq ssSeco (ssadd) ssPneu (ssadd) ssElec (ssadd) ssProc (ssadd))

;(princ "\n b ")
(if (setq ssLines (ssget "X" '((0 . "LINE,LWPOLYLINE")(8 . "secondary,pneumatic,electrical,PROCESS"))))
	(while (< cntr (sslength ssLines)) 
	(setq peName (ssname ssLines cntr))
	(setq peType (cdr (assoc 8 (entget peName))))

;	(princ "\n peName: ")(princ peName)
;	(princ "\n peType: ")(princ peType)

		(cond
			((= peType "secondary") (setq ssSeco (ssadd peName ssSeco)))
			((= peType "pneumatic") (setq ssPneu (ssadd peName ssPneu)))
			((= peType "electrical") (setq ssElec (ssadd peName ssElec)))
			((= peType "PROCESS") (setq ssProc (ssadd peName ssProc)))
			(T (princ "\n Circuit type not accounted for. "))
		) ;cond

	(setq cntr (1+ cntr))
	) ;while

	(progn (princ "\n Drawing contains no lines. ")(exit))
) ;if

;(princ "\n ssSeco: ")(princ (sslength ssSeco))
;(princ "\n ssPneu: ")(princ (sslength ssPneu))
;(princ "\n ssElec: ")(princ (sslength ssElec))
;(princ "\n ssProc: ")(princ (sslength ssProc))

;(princ "\n c ")

(princ "\n d ")
(command "_.pedit" "Multiple" ssSeco "" "Yes" "Join" "Jointype" "Both" fuzzD "" "Join" "")
(princ "\n e ")
(command "_.pedit" "Multiple" ssPneu "" "Yes" "Join" "Jointype" "Both" fuzzD "" "Join" "")
(princ "\n f ")
(command "_.pedit" "Multiple" ssElec "" "Yes" "Join" "Jointype" "Both" fuzzD "" "Join" "")
(princ "\n g ")
(command "_.pedit" "Multiple" ssProc "" "Yes" "Join" "Jointype" "Both" fuzzD "" "Join" "")
(princ "\n h ")
) ;TESTY_joinLines

Does anything stick out to you guys as an obvious problem?

 

Any help is appreciated.  Thanks!

~Z

0 Likes
Accepted solutions (1)
1,006 Views
4 Replies
Replies (4)
Message 2 of 5

rkmcswain
Mentor
Mentor

It doesn't look like you are checking/setting PEDITACCEPT. The prompts for the PEDIT command vary depending on the value of this sysvar.
R.K. McSwain     | CADpanacea | on twitter
Message 3 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

You should also make sure that your ss have some objects to join.

eg.

(if (> (sslength ssSeco) 0) (command "_.pedit" ...))

 

Message 4 of 5

zph
Collaborator
Collaborator

BeeKeeCZ,

That was the problem and the fix.  Thank you, sir!

 

0 Likes
Message 5 of 5

cadffm
Consultant
Consultant

The problem now is solved, ok  - but there is more

I already wrote it and I do not want to waste it:

 

I miss the information about the error  😉

So if you have CMDECHO = 1 and look into the text window [F2] after your test run, you should already be able to see the problem.
(Exactly this information is missing from you at the moment)

In you code you start the pedit-command for all 4 selectionsets, but "ssPneu" and "ssElec" are empty selectionsets
and at this point the pedit-command crashs (pedit want objects and you don't feed the pedit) - Check this out with cmdecho=1/[F2]



a)
PEDITACCEPT=0 isn't a good idea because you select Lines AND POLYLINES, if you have only polylines in your selectionset,
pedit will not ask about "do you want to convert", if you have not only polylines, pedit will ask you about converting.
So sometimes your code will work and sometimes not!

You should save the current peditaccept value, set peditaccept to 1 and at the end of your code
set it back to the old value - think about to edit your command pedit statements in that case)


b) not so important: WHY that blank aftes the linebreak? Thats not the usual.
(progn (princ "\n Drawing...)
(T (princ "\n Circuit type...)
Normal:
(progn (princ "\nDrawing...)
(T (princ "\nCircuit type...)


c) =
You are comparing Layernames: (= peType "secondary")
Thats possible, but think about in one file the Layername can be "Secondary" or "SECONDARY",
in that case it is often meaningful to be generous: (= (strcase peType) "SECONDARY")


d) international commands and options
Your underline at "_.pedit" isn't useful, so you can write also ".pedit", why?
_.pedit works in all language versions (english command with underline in front of = international command),
good idea to use "_.pedit" instead of just ".pedit" (which works perhaps not in all versions).
But after you started the command you fire MULTIPLE, YES and JOINTYPE, BOTH and JOIN to the command.
(command "_.pedit" "Multiple" ssProc "" "Yes" "Join" "Jointype" "Both" fuzzD "" "Join" "")
In Spain, German or French version these are no valid options 😉 So the best way is to write ALL commands and options as international call:
~ and you get more help in the forum, because we (no english versions user) don't need to edit your code, just because it isn't international  ~
*thanks*


Possible solution, ;; Run only if there are more than one object selected, changed for using peditaccept=1 (remove your "YES") and international command&options.
(if (< 1 ssSeco)
    (command "_.pedit" "_Multiple" ssSeco "" "_Join" "_Jointype" "_Both" fuzzD "" "_Join" "")  
)


Sebastian

0 Likes