How to avode double selection

How to avode double selection

danglar
Advocate Advocate
3,635 Views
32 Replies
Message 1 of 33

How to avode double selection

danglar
Advocate
Advocate

I did a little improvement of code from

https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-make-selection-set/m-p/840402...

in order to add text mask from express tools (c:textmask) and now routine can draw background wide polyline under selected polyline and also create text mask under selected text.

Program working properly but have "dirty" limitation. User need to make double selection: one for text mask and another one for polylines (see attached lisp)

I tried to change it but it was unsuccessful and one of the reasons of it I can't call needful sub functions from (c:textmask)

Is it possible to automate process and make "one shot selection" for these subroutines

Any help will be very appreciated

 

0 Likes
Accepted solutions (1)
3,636 Views
32 Replies
Replies (32)
Message 2 of 33

ВeekeeCZ
Consultant
Consultant

Well, the TEXTMASK routine is too complex to modify, so it's sort of challenging to find a way around.

 

Here is the idea how it can work. At this point the principle works good but the routine fails on some layer setting.  Hopefully, you manage to fix it and clean up your mess.

While you'll trying, don't forget that vla-sendcommand has to be LAST command!! 

 

 

;;; Draw "backgroung" wide polylines under polylines selected by user
;;; Based on routine created by BIGAL saved from: http://www.cadtutor.net/forum/showthread.php?98213-Copy-text-into-same-place-but-in-different-layer
;;; Combined and Deeply modified by Igal Averbuh 2018 (added option to copy any kind of objects and select layer to copy to)
;;; Helped by dbhunia  https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/how-to-make-selection-set/m-p/8404026#M377088
;;; Finaly modified by CADffm



;; Polyline Width  -  Lee Mac
;; Applies a given constant width to all segments in a selection of polylines.

(defun c:pw ( / *error* idx sel wid )
  
  (defun *error* ( msg )
    (LM:endundo (LM:acdoc))
    (if (and msg (not (wcmatch (strcase msg t) "*break,*cancel*,*exit*")))
      (princ (strcat "\nError: " msg))
      )
    (princ)
    )
  
  (LM:startundo (LM:acdoc))
  (if (setq sel *bg-ssp*)
    
    ;(setq sel (LM:ssget "\nSelect polylines: " '("_:L" ((0 . "LWPOLYLINE,POLYLINE")))))
    
    ;(setq sel (ssget "L" (list '(0 . "LWPOLYLINE,POLYLINE"))))
    
    (progn
      (initget 4)
      (setq wid  1.0) ;here to set wigth op backgroung polyline
      ;(setq wid (getdist "\nEnter New Width: "))
      (repeat (setq idx (sslength sel))
        (vla-put-constantwidth (vlax-ename->vla-object (ssname sel (setq idx (1- idx)))) wid)
        )
      )
    )
  (*error* nil)
  (princ)
  )

;; ssget  -  Lee Mac
;; A wrapper for the ssget function to permit the use of a custom selection prompt
;; msg - [str] selection prompt
;; arg - [lst] list of ssget arguments

(defun LM:ssget ( msg arg / sel )
  (princ msg)
  (setvar 'nomutt 1)
  (setq sel (vl-catch-all-apply 'ssget arg))
  (setvar 'nomutt 0)
  (if (not (vl-catch-all-error-p sel)) sel)
  )

;; Start Undo  -  Lee Mac
;; Opens an Undo Group.

(defun LM:startundo ( doc )
  (LM:endundo doc)
  (vla-startundomark doc)
  )

;; End Undo  -  Lee Mac
;; Closes an Undo Group.

(defun LM:endundo ( doc )
  (while (= 8 (logand 8 (getvar 'undoctl)))
    (vla-endundomark doc)
    )
  )

;; Active Document  -  Lee Mac
;; Returns the VLA Active Document Object

(defun LM:acdoc nil
  (eval (list 'defun 'LM:acdoc 'nil (vla-get-activedocument (vlax-get-acad-object))))
  (LM:acdoc)
  )
(vl-load-com) (princ)




(defun c:ccl ( / ss)
  (setvar 'CMDECHO 0)
  (princ "\n\nSelect Objects for BACKGROUND layer.")
  (if (setq ss *bg-ssp*) ;(ssget "_:L" (list '(0 . "LWPOLYLINE,POLYLINE"))))
    (progn
      (command
        "_.LAYER" "_new" "0-BACKGROUND" "_on" "0-BACKGROUND" "_thaw" "0-BACKGROUND" ""
        "_.copy" ss "" "_non" "0,0" "_non" "0,0"
        "_.chprop" "_p" "" "_layer" "0-BACKGROUND" ""
        )
      (sssetfirst nil ss)
      )
    (princ "\nNothing selected, canceled.")
    )
  (princ)
  )

(defun c:bg ( / )
  ;(setq oldclayer (getvar "clayer"))
  ;(command "-layer" "m" "0-BACKGROUND" "C" "42" "0-BACKGROUND" "")
  (c:ccl)
  (c:pw)
  (command "draworder" "P" "" "b")
  ;(command "regenall")
  ;(setvar "clayer" oldclayer)
  )


(defun c:bg2 ( / ss ps st)
  
  (if (setq ss (ssget "_:L" '((0 . "*TEXT,LWPOLYLINE"))))
    (progn
      (setq *bg-ssp* (ssadd))
      (repeat (setq i (sslength ss))
        (if (= "LWPOLYLINE" (cdr (assoc 0 (entget (setq ent (ssname ss (setq i (1- i))))))))
          (ssadd ent *bg-ssp*)))
      
      (cond ((and (> (sslength *bg-ssp*) 0) (/= (sslength *bg-ssp*) (sslength ss)))
             (vla-sendcommand (vla-get-activedocument (vlax-get-acad-object)) (strcat "TEXTMASK\rP\r\r\r\rBG\r\r" (chr 27))))
            
            (T (setq *bg-ssp* nil))))))
0 Likes
Message 3 of 33

danglar
Advocate
Advocate

first of all I want to thank you   for finding a good solution for this issue

It's took a little bit of time to check a program functionality, but after all I find some limitations in your solution

After invoking your approach the final solution looks like this:

 Capture1.JPG

in a same time previous solution looks like

Before

 

 

And after

 

 

Program make it in “two shot’s”

and I need it in “one shot”

Probable reason of this difference: text and text mask belongs to one layer or program make unnecessary copy of text entities to background layer 

program have no sensitivity to arc polylines (it works in a previous version)

sample dwg's before and after attached to reply

0 Likes
Message 4 of 33

danglar
Advocate
Advocate

before

before.jpg

and after

after.jpg

0 Likes
Message 5 of 33

ВeekeeCZ
Consultant
Consultant

Hi @danglar, I was focused only on the main issue, didn't really had time to go thru all the functionality. I was hoping you can do that yourself. If not, post some sample DWG with states before and after.

 

Edit: Oh sorry, you already did. I'll look into that.

0 Likes
Message 6 of 33

danglar
Advocate
Advocate

.. unfortunately I have been lost in a finding how to fix this issue since yesterday

just a little fix for this in BG2 subroutine

(if (setq ss (ssget "_:L" '((0 . "*TEXT,LWPOLYLINE,POLYLINE"))))

and after that condition for POLYLINE

 

(if (= "POLYLINE" (cdr (assoc 0 (entget (setq ent (ssname ss (setq i (1- i))))))))
          (ssadd ent *bg-ssp*)))

and a little remark

 

textmask in your solution use previous selection set an this is right, but c:ccl subroutine use the same selection set ( with text entities) and this is not right

probably need to separate it for c:ccl subroutine?

0 Likes
Message 7 of 33

ВeekeeCZ
Consultant
Consultant

Ok, can we recap all types of ents it should handle and what to do with them?

- text - make a solid mask

- mtext - would be that ever the case?

- lwpoly and 2dpoly - copy underneath and put the width of 1

- blocks - anything? (it does a copy underneath to bg layer of the same lineweight)

- anything else?

0 Likes
Message 8 of 33

danglar
Advocate
Advocate

OK, let's recap it all.

in addition of that you already wrote..

all kind of texts and mtexts - textmask (solid)

polylines, lwpolylines, splines, arcs and lines and circles - copy underneath and put the width of 1

leaders, multileaders and blocks - like textmask (if it possible around the external contour with preferable gap, if not - like a text entities)

The main goal of this routine is to highlight design solution on background of many existing xref’s

and all kind of entities can be included to this process

0 Likes
Message 9 of 33

ВeekeeCZ
Consultant
Consultant

Hm, I thought that I would fix that quickly, but now you moved the thing into totally different level.

So I'm out for now.

0 Likes
Message 10 of 33

danglar
Advocate
Advocate

Probably you can fix another issue..

In addition of that I wrote I make a little combination of existing routines in order to create background under selected block (see attached lisp)

It works perfect but only for one block per session and I need the same but for multiple selection

Can you help me with this?

0 Likes
Message 11 of 33

ВeekeeCZ
Consultant
Consultant

I made a routine that handles all kind of entities you listed. Even blocks. But that's an issue, because the routine you've found is very slow. So this ability is commented out (see the blue) and blocks are exploded to get its lines and texts. 

The routine is quite simple, you you can manage to make minor adjustments by yourself.

 

(vl-load-com)

; Required ExpressTools



(defun c:BG ( / *error* sel ss sst i enl sse)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (mapcar 'setvar *BG-VAR* *BG-VAL*)
    (setq *BG-doc* nil *BG-VAR* nil *BG-VAL* nil *BG-enl* nil)
    (princ))
  
  
  (if (and (setq sel (ssget "_:L" '((0 . "*TEXT,*POLYLINE,*LEADER,DIMENTION,INSERT,SPLINE,LINE,ARC,CIRCLE"))))
	   (setq *BG-enl* (entlast))
	   (setq ss (ssadd))
	   )
    
    (progn
      
      (vla-startundomark (setq *BG-doc* (vla-get-activedocument (vlax-get-acad-object))))
      (setq *BG-VAL* (mapcar 'getvar (setq *BG-VAR* '(CMDECHO OSMODE CLAYER DELOBJ PEDITACCEPT PICKSTYLE))))
      (mapcar 'setvar *BG-VAR* 		  	    '(1	      0	     "0"  	3	  1	0))
      
      (setq enl (entlast))
      (command "_.COPY" sel "" '(0 0 0) '(0 0 0))
      (while (setq enl (entnext enl))
	(ssadd enl ss))
      
      (if (setq sst (acet-ss-ssget-filter ss '((0 . "*LEADER,DIMENTION,INSERT"))))
	(progn
	  (initcommandversion)
	  (command "_.EXPLODE" sst "")))						; lwpolylines,lines,*text,solid,insert
      
      (setq enl *BG-enl* ss (ssadd))
      (while (setq enl (entnext enl))
	(if (entget enl) (ssadd enl ss)))						; revised ss - cleard of removed ents and added new ones

      
      (if (setq sst (acet-ss-ssget-filter ss '((0 . "SOLID"))))
	(command "_.ERASE" sst ""))
      
      (if (setq sst (acet-ss-ssget-filter ss '((0 . "CIRCLE"))))
	(:circle2polyline sst)) 							; lwpolylines
      
      (if (setq sst (acet-ss-ssget-filter ss '((0 . "SPLINE"))))
	(repeat (setq i (sslength sst))
	  (command "_.SPLINEDIT" (ssname sst (setq i (1- i))) "_Polyline" 10)))		; lwpolylines
      
      (if (setq sst (acet-ss-ssget-filter ss '((0 . "LINE,ARC"))))
	(command "_.PEDIT" "_Multiple" sst "" ""))						; lwpolylines
      
;;;      (if (and (setq sst (acet-ss-ssget-filter ss '((0 . "INSERT"))))
;;;	       (setq *toperror* *error*))
;;;	(repeat (setq i (sslength sst))
;;;	  (:ExternalContourOfObjects (setq sse (ssadd (ssname sst (setq i (1- i)))))))) 
      
      
      (setq enl *BG-enl* ss (ssadd))
      (while (setq enl (entnext enl))
	(if (entget enl) (ssadd enl ss)))						; revised ss - cleard of removed ents and added new ones
      
      
      (if (setq sst (acet-ss-ssget-filter ss '((0 . "*POLYLINE"))))
	(command "_.PEDIT" "_Multiple" sst "" "_Width" 1 ""))
      
      
      (if (setq sst (acet-ss-ssget-filter ss '((0 . "*TEXT"))))
	(progn
	  (acet-setvar (list "acet_textmask_masktype" "Solid" 3))  ; Save the mask type
	  (acet-setvar (list "acet_textmask_maskcolor" 42 3)) ; and the color
	  (sssetfirst nil sst))
	  (vla-sendcommand *BG-doc* (strcat "TEXTMASK\rP\r\r\r\r(BackgroundFinish)\r\r" (chr 27))))
	(BackgroundFinish))
      
      ))
  (princ)
 )
  
; ---

(defun BackgroundFinish (/ *error* ss sst enl)
  
  (defun *error* (errmsg)
    (if (not (wcmatch errmsg "Function cancelled,quit / exit abort,console break,end"))
      (princ (strcat "\nError: " errmsg)))
    (mapcar 'setvar *BG-VAR* *BG-VAL*)
    (vla-endundomark *BG-doc*)
    (setq *BG-doc* nil *BG-VAR* nil *BG-VAL* nil *BG-enl* nil *toperror* nil)
    (princ))
  
  ; ----
  
  (if *BG-enl*
    (progn
      
      (setq enl *BG-enl* ss (ssadd))
      (while (setq enl (entnext enl))
	(if (entget enl) (ssadd enl ss)))
      
      (command "_.-LAYER" "_T" "0-BACKGROUND" "_U" "0-BACKGROUND" "_M" "0-BACKGROUND" "C" 42 "0-BACKGROUND" ""
	       "_.CHPROP" ss "" "_Layer" "0-BACKGROUND" ""
	       "_.DRAWORDER" ss "" "_Back"
	       "_.REGENALL")

      (if (setq sst (acet-ss-ssget-filter ss '((0 . "*TEXT,INSERT"))))
	(command "_.ERASE" sst ""))
      
      (*error* "end")))
  (princ)
  )





;; Written by Kent Cooper
;; https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/circle-to-polyline-circular-polyline-to-circle/m-p/5520233/highlight/true#M330236
;; Mods by BeekeeCZ to make it subfunc

(defun :circle2polyline (csel / conv cir cdata cctr crad pdata ssnew)
  
  (if (and csel ; User selection
	   (setq ssnew (ssadd)))
    (repeat (sslength csel); then
      (setq cir (ssname csel 0); Circle entity name
	    cdata (entget cir); entity data
	    cctr (cdr (assoc 10 cdata)); center point, OCS for Circle & LWPolyline w/ WCS 0,0,0 as origin
	    crad (cdr (assoc 40 cdata)); radius
	    pdata (vl-remove-if-not '(lambda (x) (member (car x) '(67 410 8 62 6 48 370 39))) cdata)
	    ; start Polyline entity data list -- remove Circle-specific entries from
	    ; Circle's entity data, and extrusion direction; 62 Color, 6 Linetype, 48
	    ; LTScale, 370 LWeight, 39 Thickness present only if not default/bylayer
	    ); setq
      (ssadd (entmakex (append '((0 . "LWPOLYLINE")
				 (100 . "AcDbEntity"))
			       pdata ; remaining non-entity-type-specific entries
			       (list '(100 . "AcDbPolyline")
				     '(90 . 2); # of vertices
				     (cons 70 (1+ (* 128 (getvar 'plinegen)))); closed [the 1], and uses
				     ; current linetype-generation setting; change above line to
				     ; '(70 . 129) to force linetype generation on, '(70 . 1) to force it off
				     '(43 . 0.0); global width
				     (cons 38 (caddr cctr)); elevation in OCS above WCS origin [Z of Circle center]
				     (cons 10 (list (- (car cctr) crad) (cadr cctr))); vertex 1
				     '(40 . 0.0) '(41 . 0.0) '(42 . 1); 0 start & end widths, semi-circle bulge factor
				     (cons 10 (list (+ (car cctr) crad) (cadr cctr))); vertex 2
				     '(40 . 0.0) '(41 . 0.0) '(42 . 1)
				     (assoc 210 cdata) ; extr. dir. at end [if in middle, reverts to (210 0.0 0.0 1.0) in (entmake)]
				     )))
	     ssnew)
      (entdel cir)))
  ssnew)




;; --------------------------------------------------------------------------------------------------------------------------------------



;;; ! *********************************************************
;;; !                  lib:IsPtInView                         *
;;; ! *********************************************************
;;; ! ????????? ????????? ?? ????? ? ??????? ??????           *
;;; ! Auguments: 'pt'  — ????? ??? ??????? ? ???!!!           *
;;; ! Return   : T ??? nil ???? 'pt' ? ??????? ?????? ??? ??? *
;;; ! *********************************************************
(defun lib:IsPtInView (pt / VCTR Y_Len SSZ X_Pix Y_Pix X_Len Lc Uc)
  (setq pt (trans pt 0 1))
  (setq	VCTR  (getvar "VIEWCTR")
	Y_Len (getvar "VIEWSIZE")
	SSZ   (getvar "SCREENSIZE")
	X_Pix (car SSZ)
	Y_Pix (cadr SSZ)
	X_Len (* (/ X_Pix Y_Pix) Y_Len)
	Lc    (polar VCTR (dtr 180.0) (* 0.5 X_Len))
	Uc    (polar Lc 0.0 X_Len)
	Lc    (polar Lc (dtr 270.0) (* 0.5 Y_Len))
	Uc    (polar Uc (dtr 90.0) (* 0.5 Y_Len))
	)
  (if (and (> (car pt) (car Lc))
	   (< (car pt) (car Uc))
	   (> (cadr pt) (cadr Lc))
	   (< (cadr pt) (cadr Uc))
	   )
    T
    nil
    )
  )
(defun DTR (a) (* pi (/ a 180.0)))
(defun RTD (a) (/ (* a 180.0) pi))
;; ! **********************************************************
;; !                             lib:Zoom2Lst                 *
;; ! **********************************************************
;; ! Function : Zoom ?????? ?????? ?????                      *
;; ! Arguments: 'vlist' — ?????? ????? ? ???!!!!              *
;; ! ????????? ?????, ????? ??? ????? ???? ?????              *
;; ! Returns  : t — ???? ???????????? nil — ???               *
;; ! **********************************************************
(defun lib:Zoom2Lst (vlist / bl tr Lst OS)
  (setq	Lst (lib:pt_extents vlist)
	bl  (car Lst)
	tr  (cadr Lst)
	)
  (if (not (and (lib:IsPtInView bl) (lib:IsPtInView tr)))
    (progn (command "_.Zoom"
		    "_Window"
		    (trans bl 0 1)
		    (trans tr 0 1)
		    "_.Zoom"
		    "0.95x"
		    )
      T
      )
    NIL
    )
  )
;; ! ************************************************************
;; !           lib:pt_extents                                   *
;; ! ************************************************************
;; ! Function : ?????????? ??????? MIN, MAX X,Y,Z ?????? ?????  *
;; ! Argument : 'vlist' — ?????? ?????                          *
;; ! Returns  : ?????? ????? (??????? ?????????)                *
;; ! ************************************************************
(defun lib:pt_extents (vlist / tmp)
  (setq	tmp
	 (mapcar
	   '(lambda (x) (vl-remove-if 'null x))
	   (mapcar
	     '(lambda (what)
		(mapcar	'(lambda (x)
			   (nth what x)
			   )
			vlist
			)
		)
	     '(0 1 2)
	     )
	   )
	) ;_setq
  (list
    (mapcar
      '(lambda (x)
	 (apply 'min x)
	 )
      tmp
      )
    (mapcar '(lambda (x) (apply 'max x)) tmp)
    )
  ) ;_defun
;http://www.autocad.ru/cgi-bin/f1/board.cgi?t=30724Ed
;External contour of objects
(defun :ExternalContourOfObjects (sel /	 *error* blk     obj     MinPt   MaxPt   hiden
				  pt      pl      unnamed_block   isRus   tmp_blk adoc
				  blks    lays    lay     oname   sel     csp     loc
				  sc      ec      ret     DS      osm OS)


  (defun *error* (msg)
    (mapcar '(lambda (x)
	       (vla-put-Visible x :vlax-true))
	    hiden)
    (if	(and tmp_blk
	     (not (vlax-erased-p tmp_blk))
	     (vlax-write-enabled-p tmp_blk))
      (vla-Erase tmp_blk))
    (if OS (setvar 'OSMODE OS))
    (foreach x loc (vla-put-lock x :vlax-true))
    (*toperror* msg)
    )

  (setq OS (getvar "OSMODE"))
  (setvar "OSMODE" 0)
  
  (if
    (zerop (getvar "WORLDUCS"))
    (progn
      (vl-cmdf "_.UCS" "")
      (vl-cmdf "_.Plan" "")))
  
  (setq	isRus (= (getvar "SysCodePage") "ANSI_1251")
	adoc (vla-get-ActiveDocument (vlax-get-acad-object))
	blks (vla-get-blocks adoc)
	lays (vla-get-layers adoc))
  (if isRus
    (princ "\n???????? ??????? ??? ?????????? ???????")
    (princ "\nSelect objects for making a contour")
    )
  (if sel
    (progn
      (setq sel
	     (mapcar 'vlax-ename->vla-object
		     (vl-remove-if
		       'listp
		       (mapcar 'cadr (ssnamex sel))
		       )
		     )
	    )
      (setq csp
	     (vla-objectidtoobject
	       adoc
	       (vla-get-ownerid (car sel))
	       )
	    )
      (setq unnamed_block
	     (vla-add (vla-get-blocks adoc)
		      (vlax-3d-point '(0. 0. 0.))
		      "*U"
		      )
	    )
      (foreach x sel
	(setq oname
	       (strcase (vla-get-objectname x))
	      lay
	       (vla-item lays (vla-get-layer x))
	      )
	(if (= (vla-get-lock lay) :vlax-true)
	  (progn
	    (vla-put-lock lay :vlax-false)
	    (setq loc (cons lay loc))
	    )
	  )
	(cond
	  ((member oname '("ACDBVIEWPORT" "ACDBATTRIBUTEDEFINITION"))
	   nil
	   )
	  ((= oname "ACDBBLOCKREFERENCE")
	   (vla-InsertBlock
	     unnamed_block
	     (vla-get-insertionpoint x)
	     (vla-get-name x)
	     (vla-get-xscalefactor x)
	     (vla-get-yscalefactor x)
	     (vla-get-zscalefactor x)
	     (vla-get-rotation x)
	     )
	   (setq blk (cons x blk))
	   )
	  (t (setq obj (cons x obj)))
	  )
	) ;_foreach
      (setq lay
	     (vla-item lays (getvar "CLAYER"))
	    )
      (if
	(= (vla-get-lock lay) :vlax-true)
	(progn	(vla-put-lock lay :vlax-false)
	  (setq loc (cons lay loc))
	  )
	)
      (if obj
	(progn
	  (vla-copyobjects
	    (vla-get-activedocument
	      (vlax-get-acad-object)
	      )
	    (vlax-make-variant
	      (vlax-safearray-fill
		(vlax-make-safearray
		  vlax-vbobject
		  (cons 0 (1- (length obj)))
		  )
		obj
		)
	      )
	    unnamed_block
	    )
	  )
	)
      (setq obj (append obj blk))
      (if obj
	(progn
	  (setq	tmp_blk	(vla-insertblock
			  csp
			  (vlax-3d-point '(0. 0. 0.))
			  (vla-get-name unnamed_block)
			  1.0
			  1.0
			  1.0
			  0.0
			  )
		)
	  (vla-GetBoundingBox tmp_blk 'MinPt 'MaxPt) ;_??????? ?????
	  (setq	MinPt (vlax-safearray->list MinPt)
		MaxPt (vlax-safearray->list MaxPt)
		DS    (max (distance MinPt (list (car MinPt) (cadr MaxPt)))
			   (distance MinPt (list (car MaxPt) (cadr MinPt)))
			   )
		DS    (* 0.2 DS)	;1/5
		DS    (max DS 10)
		MinPt (mapcar '- MinPt (list DS DS))
		MaxPt (mapcar '+ MaxPt (list DS DS))
		)
	  (lib:Zoom2Lst (list MinPt MaxPt))
	  (setq sset (ssget "_C" MinPt MaxPt))
	  (if sset
	    (progn
	      (setq hiden (mapcar 'vlax-ename->vla-object
				  (vl-remove-if
				    'listp
				    (mapcar 'cadr (ssnamex sset))
				    )
				  )
		    hiden (vl-remove tmp_blk hiden)
		    )
	      (mapcar '(lambda (x) (vla-put-Visible x :vlax-false))
		      hiden
		      )
	      (setq pt (mapcar '+ MinPt (list (* 0.5 DS) (* 0.5 DS))))
	      (vl-cmdf "_.RECTANG" (trans MinPt 0 1) (trans MaxPt 0 1))
	      (setq pl (vlax-ename->vla-object (entlast)))
	      (setq sc (1- (vla-get-count csp)))
	      (if
		(VL-CATCH-ALL-ERROR-P
		  (VL-CATCH-ALL-APPLY
		    '(lambda ()
		       (vl-cmdf "_-BOUNDARY" (trans pt 0 1) "")
		       (while (> (getvar "CMDACTIVE") 0) (command ""))
		       )
		    )
		  )
		(if isRus
		  (princ "\n?? ??????? ????????? ??????")
		  (princ "\n")
		  )
		)
	      (setq ec (vla-get-count csp))
	      (while (< sc ec)
		(setq ret (append ret (list (vla-item csp sc)))
		      sc  (1+ sc)
		      )
		)
	      (setq ret (vl-remove pl ret))
	      (mapcar '(lambda (x) (vla-Erase x) (vlax-release-object x))
		      (list pl tmp_blk)
		      )
	      (setq pl nil
		    tmp_blk nil
		    )
	      (setq
		ret (mapcar '(lambda (x / mipt)
			       (vla-GetBoundingBox x 'MiPt nil) ;_??????? ?????
			       (setq MiPt (vlax-safearray->list MiPt))
			       (list MiPt x)
			       )
			    ret
			    )
		)
	      (setq ret	(vl-sort ret
				 '(lambda (e1 e2)
				    (< (distance MinPt (car e1))
				       (distance MinPt (car e2))
				       )
				    )
				 )
		    )
	      (setq pl	(nth 1 ret)
		    ret	(vl-remove pl ret)
		    )
	      (mapcar 'vla-erase (mapcar 'cadr ret))
	      (mapcar '(lambda (x) (vla-put-Visible x :vlax-true))
		      hiden
		      )
	      (foreach x loc (vla-put-lock x :vlax-true))
	      
	      
	      (if isRus
		(princ "\n?? ??????? ????????? ??????")
		(princ "\n")
		)
	      
	      )
	    )
	  )
	)
      (VL-CATCH-ALL-APPLY
	'(lambda ()
	   (mapcar 'vlax-release-object
		   (list unnamed_block tmp_blk csp blks lays)
		   )
	   )
	)
      )
    ) ;_if not
  (foreach x loc (vla-put-lock x :vlax-true))
  (vlax-release-object adoc)
  (princ)
  )
 
0 Likes
Message 12 of 33

danglar
Advocate
Advocate

Thanks for a good idea to include all kind of entities in common routine..

On this stage routine have a little syntax error with the parents and return

Command: ; error: extra right paren on input

I tried to find it but because complicating and involving many sub functions it's difficult to understand the main algorithm ...

 

Can yo fix it?

0 Likes
Message 13 of 33

danglar
Advocate
Advocate

I think I find a problem

It's here

 (vla-sendcommand *BG-doc* (strcat "TEXTMASK\rP\r\r\r\r(BackgroundFinish)\r\r" (chr 27))))
	(BackgroundFinish))
      
      ))
  (princ)
 )

need to remove a paren after the (princ)

 

0 Likes
Message 14 of 33

danglar
Advocate
Advocate

And now after I did a little "dirty" check I find some issues that I can't understand

1. routine not returned the text mask (I checked it on some drawings)

2. I find drawing that routine can't handle (see attached dwg)

in circle2polyline function need to make follow modification 

     '(43 . 1.0); global width

paragraph 1 mode important for me than 2...

0 Likes
Message 15 of 33

ВeekeeCZ
Consultant
Consultant

Hi, test this one. Fixed the errors you mentioned, some other things too. 

 

For some reason it skips one block from your example... but if you run it once more on this one, it will make it too.

0 Likes
Message 16 of 33

danglar
Advocate
Advocate

Thanks for your efforts 

 

0 Likes
Message 17 of 33

danglar
Advocate
Advocate

this fix can partly repair the situation in temp2.dwg

(if (setq sst (acet-ss-ssget-filter ss '((0 . "*POLYLINE"))))
	(command "_.LAYER" "_new" "0-BACKGROUND" "_on" "0-BACKGROUND" "_thaw" "0-BACKGROUND" ""
             "_.copy" sst "" "_non" "0,0" "_non" "0,0"
             "_.chprop" "_p" "" "_layer" "0-BACKGROUND" "" "_.PEDIT" "_Multiple" sst "" "_Width" 1 ""))
0 Likes
Message 18 of 33

danglar
Advocate
Advocate

probably need to return exploded blocks, dimensions and leaders after creation of new selection set..

(if (setq sst (acet-ss-ssget-filter ss '((0 . "*LEADER,DIMENSION,INSERT"))))
	(progn
	  (command "._copybase" "0,0,0" sst "")
	  (initcommandversion)
	  (command "_.EXPLODE" sst "")))						; creates new lwpolylines,lines,*text,solid,insert
  
      (setq enl *BG-enl* ss (ssadd))
      (while (setq enl (entnext enl))
	(if (entget enl) (ssadd enl ss)))						; revised ss - cleared from removed ents and added new ones

          (command "._pasteclip" "0,0,0")
0 Likes
Message 19 of 33

ВeekeeCZ
Consultant
Consultant
Accepted solution

Ok, one more update.

 

The main issue was one less <enter> for the TEXTMASK than needed. (accidentally removed)

TEXTMASK\rP\r\r\r\r

 

And thanks for that typo. That word was suspicious to my eyes, simply looked bad, but I couldn't figure out what's that.

 

And about your temp1 file. This drawing has simply too many blocks for your contour sub-routine. And what's even worse, this sub crashes on some of those. I really don't want to dive into that sub. So I made a workaround to our routine that you can pick whether blocks would be EXPLODED (just once) and then its entities would be covered in next process. If there is some inner block (like an arrow head) would be ignored for background and later erased.

 

The "Returning" of blocks is really not necessary because the first thing the routine does is the COPY of the selection. Then the routine works with copies only and the originals are untouched.

 

Changing properties like LAYER and LTYPE is handled by BackgroundFinish routine for all NEW entities as the very last thing - sure, if the routine does not crashes in between.

Message 20 of 33

danglar
Advocate
Advocate

Thanks again   

for your efforts. Now we are very close to final solution of this issue.

It's took me a couple of hours to check deeply your approach an find some limitations

1. In a case of "Contour" in blocks selection sub routine program functionality become very slow and even Couse to autocad to stop working (not responding issue)

My suggestion to eliminate "Contour" sub function at all - it's unnecessary

2. It's a clever thing to clean the "garbage" (I mean after blocks, dimensions and leaders exploding)

probably will be better to use (c:burst) express tools function in order to convert attributes to text entities?

probably this approach can be useful for "cleaning" and "drawordering" in a same time

(defun c:drb ( / i s )
    (if (setq s (ssget "_X" '((8 . "0-BACKGROUND"))))
        (command "draworder" s "" "b")
    )
    (princ)
)

(defun c:er0 ( / i s )
    (if (setq s (ssget "_X" '((8 . "0"))))
        (command "_erase" s "")
    )
    (princ)
)


(defun c:dro ( / )
(setq oldclayer (getvar "clayer"))
(c:drb)
(c:er0)
(command "regenall")
(setvar "clayer" oldclayer)
)

Your opinion is very important for me

 

0 Likes