Condition function not working running sectioned option

Condition function not working running sectioned option

jsaayman
Advocate Advocate
943 Views
4 Replies
Message 1 of 5

Condition function not working running sectioned option

jsaayman
Advocate
Advocate

Please could somebody help me figure out why my script won't run. I think it has something to do with the 

cond

function

 

(defun c:PDFPRINT ( / atb_blk dwgno rev _cetype)

(initget "Current All")
(setq _cetype (cond ((getkword "\nEnter print option [Current layout/All layouts] <Current>: ")) ("Current")))  
    (vl-load-com)
  
(if (not path)
   (progn 	; then clause
   	(setq path (LM:browseforfolder "Select Folder" "" 0))
   ); end progn
   path
 ) ;end if
;;;    (if (setq atb_blk (car (entsel)))
;;;      (progn
	(cond
	  ((= _cetype "Current")
	   (if
	   (setq atb_blk (car (entsel)))
		(setq dwgno (LM:vl-getattributevalue atb_blk "SUBEPCDWGNO."))
		(setq rev (LM:vl-getattributevalue atb_blk "REV"))
		(COMMAND "ZOOM" "E")
	   	(setq psize (papersize))
	   	(princ psize)
	    	(COMMAND "-PLOT"
			"Y"
			""
			"DWG To PDF.pc3"
			"ISO A0 (841.00 x 1189.00 MM)"
			""
			""
			""
			""
			""
			""
			"Y"
			""
			"Y"
			"N"
			"N"
			"N"
    			(strcat path "\\" dwgno " Rev "rev ".pdf")
			;;""; Name of file
			"N"
			"y"
	      	)

	   );end if
	)
	((= _cetype "All")
	 (setq atb_blk (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
	 (foreach lay (layoutlist)
	   (setvar "ctab" lay)
	   (COMMAND "LAYOUT" "SET" lay)
	   (COMMAND "ZOOM" "E")
		(if (setq ss (ssget "x" (list (cons 0 "INSERT") (cons 2 atb_blk))))
   		(progn
    		(setq dwgno (LM:vl-getattributevalue atb_blk "SUBEPCDWGNO."))
		(setq rev (LM:vl-getattributevalue atb_blk "REV"))
		(COMMAND "-PLOT"
			"Y"
			""
			"DWG To PDF.pc3"
			"ISO A0 (841.00 x 1189.00 MM)"
			""
			""
			""
			""
			""
			""
			"Y"
			""
			"Y"
			"N"
			"N"
			"N"
    			(strcat path "\\" dwgno " Rev "rev ".pdf"); Name of file
			"N"
			"y"
	      	)

		  )
 		)
		); foreach
	 )
      	);end cond
      (princ "\nNothing selected")
      )
    (princ)
)

(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
       pth
    )
)


(defun LM:vl-getattributevalue ( blk tag )
    (setq tag (strcase tag))
    (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke (vlax-ename->vla-object blk) 'GetAttributes))
)

(defun papersize (/ psn scale)
  (setq
    psn	(member	'(100 . "AcDbPlotSettings")
		(dictsearch
		  (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
		  (getvar "ctab")
		)
	)
  )
  (if (= (caadr psn) 1) ; Page Setup Name exist
    (progn (setq scale (if (= 0 (cdr (assoc 72 psn)))
			 25.4
			 1.0
		       )
	   )
	   (strcat (rtos (/ (cdr (assoc 44 psn)) scale) 2 2)
		   " x "
		   (rtos (/ (cdr (assoc 45 psn)) scale) 2 2)
	   )
    )
  )
)
0 Likes
Accepted solutions (1)
944 Views
4 Replies
Replies (4)
Message 2 of 5

ВeekeeCZ
Consultant
Consultant

@jsaayman wrote:

Please could somebody help me figure out why my script won't run. I think it has something to do with the 

cond

function

 

(defun c:PDFPRINT ( / atb_blk dwgno rev _cetype)

(initget "Current All")
(setq _cetype (cond ((getkword "\nEnter print option [Current layout/All layouts] <Current>: ")) ("Current")))  
    (vl-load-com)
  
(if (not path)
   (progn 	; then clause
   	(setq path (LM:browseforfolder "Select Folder" "" 0))
   ); end progn
   path
 ) ;end if
;;;    (if (setq atb_blk (car (entsel)))
;;;      (progn
	(cond
	  ((= _cetype "Current")
	   (if
	   (setq atb_blk (car (entsel)))
		(setq dwgno (LM:vl-getattributevalue atb_blk "SUBEPCDWGNO."))
		(setq rev (LM:vl-getattributevalue atb_blk "REV"))
		(COMMAND "ZOOM" "E")
	   	(setq psize (papersize))
	   	(princ psize)
	    	(COMMAND "-PLOT"
			"Y"
			""
			"DWG To PDF.pc3"
			"ISO A0 (841.00 x 1189.00 MM)"
			""
			""
			""
			""
			""
			""
			"Y"
			""
			"Y"
			"N"
			"N"
			"N"
    			(strcat path "\\" dwgno " Rev "rev ".pdf")
			;;""; Name of file
			"N"
			"y"
	      	)

	   );end if
	)
	((= _cetype "All")
	 (setq atb_blk (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
	 (foreach lay (layoutlist)
	   (setvar "ctab" lay)
	   (COMMAND "LAYOUT" "SET" lay)
	   (COMMAND "ZOOM" "E")
		(if (setq ss (ssget "x" (list (cons 0 "INSERT") (cons 2 atb_blk))))
   		(progn
    		(setq dwgno (LM:vl-getattributevalue atb_blk "SUBEPCDWGNO."))
		(setq rev (LM:vl-getattributevalue atb_blk "REV"))
		(COMMAND "-PLOT"
			"Y"
			""
			"DWG To PDF.pc3"
			"ISO A0 (841.00 x 1189.00 MM)"
			""
			""
			""
			""
			""
			""
			"Y"
			""
			"Y"
			"N"
			"N"
			"N"
    			(strcat path "\\" dwgno " Rev "rev ".pdf"); Name of file
			"N"
			"y"
	      	)

		  )
 		)
		); foreach
	 )
      	);end cond
;      (princ "\nNothing selected")
;      )
    (princ)
)

(defun LM:browseforfolder ( msg dir bit / err fld pth shl slf )
    (setq err
        (vl-catch-all-apply
            (function
                (lambda ( / app hwd )
                    (if (setq app (vlax-get-acad-object)
                              shl (vla-getinterfaceobject app "shell.application")
                              hwd (vl-catch-all-apply 'vla-get-hwnd (list app))
                              fld (vlax-invoke-method shl 'browseforfolder (if (vl-catch-all-error-p hwd) 0 hwd) msg bit dir)
                        )
                        (setq slf (vlax-get-property fld 'self)
                              pth (vlax-get-property slf 'path)
                              pth (vl-string-right-trim "\\" (vl-string-translate "/" "\\" pth))
                        )
                    )
                )
            )
        )
    )
    (if slf (vlax-release-object slf))
    (if fld (vlax-release-object fld))
    (if shl (vlax-release-object shl))
    (if (vl-catch-all-error-p err)
        (prompt (vl-catch-all-error-message err))
       pth
    )
)


(defun LM:vl-getattributevalue ( blk tag )
    (setq tag (strcase tag))
    (vl-some '(lambda ( att ) (if (= tag (strcase (vla-get-tagstring att))) (vla-get-textstring att))) (vlax-invoke (vlax-ename->vla-object blk) 'GetAttributes))
)

(defun papersize (/ psn scale)
  (setq
    psn	(member	'(100 . "AcDbPlotSettings")
		(dictsearch
		  (cdr (assoc -1 (dictsearch (namedobjdict) "ACAD_LAYOUT")))
		  (getvar "ctab")
		)
	)
  )
  (if (= (caadr psn) 1) ; Page Setup Name exist
    (progn (setq scale (if (= 0 (cdr (assoc 72 psn)))
			 25.4
			 1.0
		       )
	   )
	   (strcat (rtos (/ (cdr (assoc 44 psn)) scale) 2 2)
		   " x "
		   (rtos (/ (cdr (assoc 45 psn)) scale) 2 2)
	   )
    )
  )
)

Red because of the blue. Try, didn't test it.

0 Likes
Message 3 of 5

jsaayman
Advocate
Advocate

@ВeekeeCZ Thanks but that didn't solve the problem

0 Likes
Message 4 of 5

ВeekeeCZ
Consultant
Consultant
Accepted solution

I see, remove the IF from the first cond.

I guess the code was not written by you but you did some later adjustments, right? Then either tell us what you did or post some test drawing.

 

((= _cetype "Current")
       (setq atb_blk (car (entsel)))
       (setq dwgno (LM:vl-getattributevalue atb_blk "SUBEPCDWGNO."))
       (setq rev (LM:vl-getattributevalue atb_blk "REV"))
       (COMMAND "ZOOM" "E")
       (setq psize (papersize))
       (princ psize)
       (COMMAND "-PLOT"
		"Y"
		""
		"DWG To PDF.pc3"
		"ISO A0 (841.00 x 1189.00 MM)"
		""
		""
		""
		""
		""
		""
		"Y"
		""
		"Y"
		"N"
		"N"
		"N"
		(strcat path "\\" dwgno " Rev "rev ".pdf")
		;;""; Name of file
		"N"
		"y"
		))

 

0 Likes
Message 5 of 5

dbhunia
Advisor
Advisor

Hi

 

I am also agree with @ВeekeeCZ

 

Here is your "Cond" loop....

 


@jsaayman wrote:

Please could somebody help me figure out why my script won't run. I think it has something to do with the 

cond

 

....................

 

(defun c:PDFPRINT ( / atb_blk dwgno rev _cetype path)
(initget "Current All")
(setq _cetype (cond ((getkword "\nEnter print option [Current layout/All layouts] <Current>: ")))); ("Current")))  
    (vl-load-com)
(if (not path)
   (progn 	; then clause
   	(setq path (LM:browseforfolder "Select Folder" "" 0))
   ); end progn
   path
 ) ;end if
;;    (if (setq atb_blk (car (entsel)))
;;      (progn
	(cond
	   ((= _cetype "Current")
                (setq atb_blk (car (entsel)))
		(setq dwgno (LM:vl-getattributevalue atb_blk "SUBEPCDWGNO."))
		(setq rev (LM:vl-getattributevalue atb_blk "REV"))
 		(COMMAND "ZOOM" "E")
	   	(setq psize (papersize))
	   	(princ psize)
	    	(COMMAND "-PLOT"
			"Y"
			""
			"DWG To PDF.pc3"
			"ISO A0 (841.00 x 1189.00 MM)"
			""
			""
			""
			""
			""
			""
			"Y"
			""
			"Y"
			"N"
			"N"
			"N"
    			(strcat path "\\" dwgno " Rev "rev ".pdf")
			;;""; Name of file
			"N"
			"y"
	      	)
	      ); end ((= _cetype "Current")
	;)
	((= _cetype "All")
	 (setq atb_blk (vla-get-effectivename (vlax-ename->vla-object (car (entsel "\nSelect block: ")))))
	 (foreach lay (layoutlist)
	   (setvar "ctab" lay)
	   (COMMAND "LAYOUT" "SET" lay)
	   (COMMAND "ZOOM" "E")
		(if (setq ss (ssget "x" (list (cons 0 "INSERT") (cons 2 atb_blk))))
   		(progn
    		(setq dwgno (LM:vl-getattributevalue atb_blk "SUBEPCDWGNO."))
		(setq rev (LM:vl-getattributevalue atb_blk "REV"))
		(COMMAND "-PLOT"
			"Y"
			""
			"DWG To PDF.pc3"
			"ISO A0 (841.00 x 1189.00 MM)"
			""
			""
			""
			""
			""
			""
			"Y"
			""
			"Y"
			"N"
			"N"
			"N"
    			(strcat path "\\" dwgno " Rev "rev ".pdf"); Name of file
			"N"
			"y"
	      	)

		  )
 		)
		); foreach
	 )
      	);end cond

(princ "\nNothing selected")
(princ)
)

 


Debashis Bhunia
Co-Founder of Geometrifying Trigonometry(C)
________________________________________________
Walking is the First step of Running, Technique comes Next....
0 Likes