Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

putting inserts in paperspace

0 REPLIES 0
Reply
Message 1 of 1
wkmvrij
460 Views, 0 Replies

putting inserts in paperspace

Good afternoon to all,


With the following code I try to achieve the placement of partnumber balloons and a BOM line in layouts of my drawing.Through the use of a template file I have 3 layouts available each with an insert present of a block called "bomblock" . The partnumber balloons and the BOM are always in Paperspace!

This codes works only if I go to the layout which is first in the row of tabs allowing to select a layout and start my partnumbering here. Any other way it seems to lose track of the place in the layout->block where I happen to work, placing a new insert in the wrong layout and subsequently updating this inserts' atributes in yet another instance of an insert, even on another layout.

The code is triggerd (with a button on a toolbar) once per partnumber.


What am I missing?


;| ===============================================================================
Function (pnum)
Created by Willem van Rij, Brix Engineering
Date feb 2014
Status test
-------------------------------------------------------------------------------
Action create a BOM above cartouch and asks for placement of Partnumber balloon
Return

Remark
---------------------------------------------------------------------------------
|;

(defun pnum (/ atts dcl_id i res l_o_blok inspoint bl attribvals dcl)
(vl-load-com)
(setq *acad-object* nil) ; Initialize global variable
(defun acad-object ()
(cond (*acad-object*) ; Return the cached object
(t
(setq *acad-object* (vlax-get-acad-object))
)
)

)

(setq *active-document* nil) ; Initialize global variable
(defun active-document ()
(cond (*active-document*) ; Return the cached object
(t
(setq *active-document* (vla-get-activedocument (acad-object)))
)
)

)

(setq *model-space* nil) ; Initialize global variable
(defun model-space ()
(cond (*model-space*) ; Return the cached object
(t
(setq *model-space* (vla-get-modelspace (active-document)))
)
)

)
(setq *paper-space* nil) ; Initialize global variable
(defun paper-space ()
(cond (*paper-space*) ; Return the cached object
(t
(setq *paper-space* (vla-get-paperspace (active-document)))
)
)

)
(VLA-put-ActiveSpace (active-document) acPaperSpace)

(setq dcl "D:\\AC2007\\lsp\\bom.dcl"
l_o_blok
(vla-get-block (vla-get-activelayout (active-document)))

i 0

)
(WriteDCL dcl (vla-get-name (vla-get-layout l_o_blok)))
(setq dcl_id (LOAD_DIALOG dcl))


(vlax-for res l_o_blok
(if (and
(= (vla-get-objectname res) "AcDbBlockReference")
(= (vla-get-name res) "bomblock")
(= (vla-get-hasattributes res) :vlax-true)
)
(progn
(setq atts (vlax-safearray->list
(VLAX-VARIANT-VALUE (vla-GetAttributes res))
)
)
(mapcar '(lambda (x)
(if (= (STRCASE (VLA-GET-TAGSTRING x)) "POS")
(if
(= (strcase (VLA-GET-TEXTSTRING x))
"-"
)
(progn (setq i 0
inspoint (vla-get-insertionpoint res)
)
)
(if (< i (atoi (VLA-GET-TEXTSTRING x)))
(setq i (atoi (VLA-GET-TEXTSTRING x))
inspoint (vecadd (vla-get-insertionpoint res)
(vlax-3d-point '(0 8 0))
)

)
)
)
)
)
atts
)

)
)
)
(NEW_DIALOG "pos_num" dcl_id)
(SET_TILE "pos" (ITOA (1+ i)))
(ACTION_TILE
"accept"
"(progn (setq attribvals (get_dcl)) (done_dialog))"
) ;_ end of action_tile
(START_DIALOG)
(UNLOAD_DIALOG dcl_id)
(setq bl
(VLA-INSERTBLOCK
l_o_blok inspoint "BOMBLOCK" 1 1 1 0)
atts (vlax-safearray->list
(VLAX-VARIANT-VALUE (vla-GetAttributes bl))
)
)
(MAPCAR '(LAMBDA (x)
(VLA-PUT-TEXTSTRING
x
(CDR (ASSOC (VLA-GET-TAGSTRING x) attribvals))
) ;_ end of vla-put-textstring
) ;_ end of lambda
atts

)
(balloon (ITOA (1+ i)))
)


;|---------------------------------------------------------------------|;

(DEFUN get_dcl (/ res)
(SETQ res (LIST (CONS "POS" (ATOI (GET_TILE "pos")))
(CONS "N_OFF" (ATOI (GET_TILE "noff")))
(CONS "DESC" (GET_TILE "def"))
(CONS "REF" (GET_TILE "bw"))
) ;_ end of list
) ;_ end of setq
(REVERSE res)
) ;_ end of DEFUN

;|---------------------------------------------------------------------|;

(DEFUN BALLOON (BALLOON_DEFTXT / A A1 H R i l_ent ssl ss)
(PRINC "Place part number balloon: ")
(COMMAND "_.LAYER" "_MAKE" "POSNUMS" "")
(SETQ pdefs '("10" "45%" "phead" "1")
ss (SSADD)
) ;_ end of setq
(SETQ
H (* (ATOF (CAR pdefs))
(/ (ATOF (SUBSTR (CADR pdefs) 1 (- (STRLEN (CADR pdefs)) 1)))
100
) ;_ end of /
) ;_ end of *
) ;_ end of setq
(SETQ R (/ (ATOF (CAR pdefs)) 2))
(SETQ ssl (SSLENGTH ss))
(SETQ A (GETPOINT "\nFrom Point: "))
(COND ((= (CADDR pdefs) "phead")
(COMMAND "color"
"white"
)
(COMMAND "_DONUT" "0" "1.5" A "")

;; (command "") ;_ end of command
(SSADD (ENTLAST) ss)
)
) ;_ end of cond
(WHILE A
(SETQ A1 (GETPOINT A "\nTo point: "))
(IF (NULL (NULL A1))
(PROGN
(IF (AND (= (- ssl (SSLENGTH ss)) 0) (= (CADDR pdefs) "ahead"))
(PROGN (COMMAND "color"
"white"
"_.INSERT"
(STRCAT BWAPPLIC_PATH "iahead")
A
(ATOF (CADDDR pdefs))
(ATOF (CADDDR pdefs))
(rtod (ANGLE A A1))
) ;_ end of command
(SSADD (ENTLAST) ss)
) ;_ end of progn
) ;_ end of if
(COMMAND "color" "white" "_.line" A A1 "")
(SSADD (ENTLAST) ss)
(SETQ A A1
A1 nil
) ;_ end of setq
) ;_ end of progn
(PROGN (COMMAND "_.color" "magenta")
(SETQ l_ent (SSNAME ss (- (SSLENGTH ss) 1))
A (CDR (ASSOC 10 (ENTGET l_ent)))
A1 (CDR (ASSOC 11 (ENTGET l_ent)))
ss (SSDEL l_ent ss)
) ;_ end of setq
(ENTDEL l_ent)
(COMMAND "_.text" "J" "M" A1 H "0" BALLOON_DEFTXT)
(SSADD (ENTLAST) ss)
(COMMAND "_.color" "yellow")
(COMMAND "_.circle" A1 R)
(SSADD (ENTLAST) ss)
(COMMAND "_.color" "white")
(COMMAND "_.line"
A
(POLAR A (ANGLE A A1) (- (DISTANCE A A1) R))
""
) ;_ end of command
(SSADD (ENTLAST) ss)
(SETQ A nil
A1 nil
) ;_ end of setq
) ;_ end of progn
) ;_ end of if
) ;_ end of while
(SETQ i 0)
ss
) ;_ end of defun

(defun WriteDCL (fname titel / fh)
;;; (findfile fname)
(and
(setq fh (open fname "w"))
(foreach str
(list
"//------------=={ BOM.dcl Dialog Definition }==-----------//"
"// //"
"// Author: Lee Mac, Copyright © 2011 - www.lee-mac.com //"
"//----------------------------------------------------------//"
""
(strcat "pos_num :dialog{label =\""
(vla-get-name (vla-get-layout l_o_blok))
"\";"
)
":column{:boxed_row { label = \"General:\";"
": edit_box {key = \"pos\"; label = \"&Partnumber\"; width = 20; fixed_width = true;}"
": edit_box { key = \"noff\"; label = \"&Number off\"; width = 20; fixed_width = true;}}"
": boxed_row {label = \"Description:\";"
": edit_box { key = \"def\"; label = \"&Definition \";width = 50;fixed_width = true;edit_limit = 60;}}"
": boxed_row {label = \"References:\"; : edit_box { key =\"bw\"; label = \"&Referentie\"; width = 50; action = \"(setq activetile $key)\"; fixed_width = true; edit_limit = 60; }}}"
" ok_cancel;}"

"//----------------------------------------------------------//"
"// End of File //"
"//----------------------------------------------------------//"

)
(write-line str fh)
)
(setq fh (close fh))
)
)

Tags (2)
0 REPLIES 0

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost