Author Topic: a routine to CONVERT DYNAMIC BLOCKS to STATIC BLOCKS  (Read 2906 times)

0 Members and 1 Guest are viewing this topic.

domenicomaria

  • Swamp Rat
  • Posts: 723
a routine to CONVERT DYNAMIC BLOCKS to STATIC BLOCKS
« on: October 09, 2020, 03:44:55 AM »
I need a routine that CONVERTS
DYNAMIC BLOCKS into STATIC BLOCKS

But these blocks contain NESTED dynamic blocks.

And there are MORE levels of NESTING.

I need a routine that converts
ALL NESTED BLOCKS too !

I believe I am able to do it.

but maybe someone has already done it ! 8-)

ronjonp

  • Needs a day job
  • Posts: 7526

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

framednlv

  • Newt
  • Posts: 64
Re: a routine to CONVERT DYNAMIC BLOCKS to STATIC BLOCKS
« Reply #2 on: October 09, 2020, 10:30:18 AM »
In MEP autocad there is a right click option to "Copy Block Definition and Assign..." command.  You can then use "Blockreplace" to update existing blocks.

domenicomaria

  • Swamp Rat
  • Posts: 723
Re: a routine to CONVERT DYNAMIC BLOCKS to STATIC BLOCKS
« Reply #3 on: October 15, 2020, 06:46:26 AM »
It seems to WORK !

I will be happy
if somebody will TEST DEEPLY IT and will IMPROVE the CODE

It is VERY USEFUL  to  NOT SHARE our DYNAMIC BLOCKS,
that sometime are complicated and need a lot of time to be created.

This code CONVERTS BLOCKS (DYNAMIC and STATIC)
that contains NESTED DYNAMIC BLOCKS
with ANY KIND of STUCTURE and LEVELS of NESTED TREES.

Please, use the attached DWG, to begin the tests.

Let me know something, please.

Domenico Maria PISANO
« Last Edit: October 15, 2020, 07:09:07 AM by domenicomaria »

d2010

  • Bull Frog
  • Posts: 323
Re: a routine to CONVERT DYNAMIC BLOCKS to STATIC BLOCKS
« Reply #4 on: October 15, 2020, 05:33:49 PM »
It seems to WORK !I will be happy
I append two command/s  to one-command.Can you test on your'drawing?
Code: [Select]
When you failed , you execute (asserte nil) at line-command.
 When you failed , you execute (princ setmypid)
My brother is taller than my cousin.Yesterday was the warmest day. My brother-in -law is a nice person, but my sister is nicer.Big attractive green eyes and a nice big old horse.
Code - Auto/Visual Lisp: [Select]
  1.  (setq acad_iso11w100-extmin 41 acad_iso11w100-extmax 60265)
  2.  (setq acad_isoQsortTime 00:00.00)
  3.  (setq runiftry11w100 (list (cons "0x0000" "c:/vlaxcompil/0user/dynamictostatic.lsp")
  4.  (cons "0x2ABB"  "append");;County.xml=4
  5.  (cons "0x6E00"  "alert");;County.xml=4
  6.  (cons "0x4843"  "j_i2s_nestedblock");;County.xml=3
  7.  (cons "0x898A"  "vl_load_com");;County.xml=3
  8.  (cons "0x73A6"  "vlax-property-available-p");;County.xml=2
  9.  (cons "0x4CA5"  "vla-get-isdynamicblock");;County.xml=2
  10.  (cons "0x8C12"  "terpri");;County.xml=2
  11.  (cons "0x0029"  "vlax-ename->vla-object");;County.xml=2
  12.  (cons "0x1F2F"  "vla-converttostaticblock");;County.xml=2
  13.  (cons "0x0616"  "assert_cxx");;County.xml=2
  14.  (cons "0x066C"  "read");;County.xml=2
  15.  (cons "0x1282"  "j_tableswitch");;County.xml=2
  16.  (cons "0x9A2E"  "dfn_real_frac");;County.xml=2
  17.  (cons "0x679B"  "getint");;County.xml=2
  18.  (cons "0xAE85"  "vla-get-blocks");;County.xml=2
  19.  (cons "0x3F98"  "vla-item");;County.xml=1
  20.  (cons "0xD367"  "vla-get-name");;County.xml=1
  21.  (cons "0xD0B1"  "ssget");;County.xml=1
  22.  (cons "0x48F2"  "ssname");;County.xml=1
  23.  (cons "0x864B"  "atof");;County.xml=1
  24.  (cons "0xEB69"  "j_dup2remove");;County.xml=1
  25.  (cons "0x0C82"  "j_imul");;County.xml=1
  26.  (cons "0x1C2B"  "setvar");;County.xml=1
  27.  (cons "0xDC92"  "entget");;County.xml=1
  28.  (cons "0xD7A9"  "j_i2s");;County.xml=1
  29.  (cons "0x428D"  "tblsearch");;County.xml=1
  30.  (cons "0x4E37"  "getvar");;County.xml=1
  31.  (cons "0x0274"  "numberp");;County.xml=1
  32.  (cons "0x28FD"  "vl-prin1-to-string");;County.xml=1
  33.  (cons "0xA6AF"  "entsel");;County.xml=1
  34.  (cons "0x1344"  "dfn_cad_asysset");;County.xml=1
  35.  (cons "0x252B"  "vla-get-objectname");;County.xml=1
  36.  (cons "0x4DFA"  "cons");;County.xml=1
  37.  (cons "0x0BF6"  "vla-get-effectivename");;County.xml=1
  38.  (cons "0x4C2D"  "sslength");;County.xml=1
  39.  (cons "0x0DC3"  "assoc");;County.xml=1
  40. ))
  41. (setq getmypid (list "0xD438") setmypid "http://www.youtube.com/watch?v=rq9AbDbN4Mc&feature=related")
  42. (defun js_dup35(mypid loopwne / rom subf)
  43.    (setq getmypid setmypid setmypid (substr mypid 8) subf (cdr (assoc (strcat "0x" (substr mypid 3 4)) runiftry11w100)))
  44.    (setq rom (apply (read subf) loopwne))
  45. rom)
  46.  (setq acad_isoQsortTimp 00:00.00)
  47.  (setq acad_isoSortTotal 00:00.00)
  48.  (princ)
  49.  ;;;{$R dfn_cad_amain}
  50.  
  51. (defun assert_cxx (/ $rr)
  52.   (setq;|a899|;
  53.          acad__assertNo 0
  54.          kHereAiciHeirIciAqui 93)
  55. )
  56. ;;{--}
  57. (Defun asserte(mssg / $rr)
  58.   (if (=  erlsp nil) (js_dup35 "0x0616:C001" (list )) (if (/= (type acad__assertNo) (quote INT)) (setq;|a3068|;
  59.          acad__assertNo 0))) (if (/= mssg nil) (setq;|a3112|;
  60.          erprv erlsp
  61.          acad__assertNo (+ acad__assertNo 1)
  62.          erlsp (strcat (js_dup35 "0x28FD:C002" (list  mssg)) ":" (itoa acad__assertNo))) (foreach $rr (list "\nAssertE=" erlsp "*" erprv) (princ $rr))) (if (>= acad__assertNo kHereAiciHeirIciAqui) (js_dup35 "0x6E00:C003" (list  (strcat "Hi! eBreakPoint kHereAiciHeirIciAqui=" (itoa kHereAiciHeirIciAqui)))))
  63. erlsp)
  64. ;;;Inf: Here is starting routine
  65. (prompt "\nCommand.com=D2S[enter]\n")
  66. (DeFun C:D2S()
  67.   (js_dup35 "0x0616:C004" (list )) (js_dup35 "0x1344:C005" (list ))
  68.  
  69.   ;;;{$R (call_stas)}
  70. ;------------------------Stdcall pp_domenicomaria
  71.   (setq _ax (pp_domenicomaria ))
  72. ;------------------------
  73.  ;;;{$R -cad_amain_callend}
  74. ;;;rem:----------------------------------------------------------------------
  75.   (command) (princ "\nEnd")
  76. rr)
  77. ;;;rem:---User Labels----cad_aPages-----
  78. ;;;rem:---pp_domenicomaria----cad_aPages-----
  79.   ;;;{$R dfn_cad_asysset}
  80. (defun dfn_cad_asysset( / $rr)
  81.   (setq su "")
  82.    (js_dup35 "0x1C2B:C006" (list  "MODEMACRO" (strcat su " ")))
  83. $rr)
  84.  ;;;{$E}
  85. ;lib:free
  86.   ;;;{$R pp_domenicomaria}
  87.  
  88. (Defun pp_domenicomaria( / $rr ldc pDrawCtx)
  89.    (js_dup35 "0x898A:C007" (list )) (setq;|a6325|;
  90.          pDrawCtx "\nGiSelector.h (2.Multiple)(1.one toStatic)(8.Quit)(7.readme): "
  91.          ldc (js_dup35 "0x679B:C008" (list  pDrawCtx))) (progn (while (<  ldc 8) (if (=  ldc 2) (js_dup35 "0x0C82:C009" (list )) (if (=  ldc 1) (js_dup35 "0xD7A9:C010" (list )) (if (=  ldc 7) (js_dup35 "0x6E00:C011" (list  readme.txt))))) (setq;|a6475|;
  92.          ldc (js_dup35 "0x679B:C012" (list  pDrawCtx)))))
  93. $rr)
  94.  ;;;{$E}
  95. ;lib:free
  96.   ;;;{$R j_imul}
  97.  
  98. ;;;Inf:Dynamic 2 StaticMultiple
  99. (defun j_imul ( / laload lstore ind nv4prep sse3 codeblocks emms item ldcw)
  100.    (js_dup35 "0x898A:C013" (list )) (setq;|a9548|;
  101.          ind 0
  102.          sse3 (js_dup35 "0xD0B1:C014" (list  (list (js_dup35 "0x4DFA:C015" (list  0 "INSERT")))))
  103.          laload (if sse3 (js_dup35 "0xAE85:C016" (list  con_acdoc)) nil)) (if laload (progn (setq;|a9658|;
  104.          nv4prep (js_dup35 "0x4C2D:C017" (list  sse3))) (while (<  ind nv4prep) (progn  (setq;|a9708|;
  105.          emms (js_dup35 "0x48F2:C018" (list  sse3 ind))
  106.          codeblocks (js_dup35 "0x0029:C019" (list  emms))
  107.          lstore (js_dup35 "0x2ABB:C020" (list  (js_dup35 "0x4843:C021" (list  laload codeblocks)) (list codeblocks)))) (foreach item lstore (setq;|a9844|;
  108.          ldcw (if (=  (js_dup35 "0x4CA5:C022" (list  item)) vlax_true) (js_dup35 "0x1F2F:C023" (list  item (js_dup35 "0x1282:C024" (list  "BLOCK" "STATIC-")))) nil)))) (setq;|a9920|;
  109.          ind (+ ind 1))))) (if laload (js_dup35 "0x8C12:C025" (list )) (js_dup35 "0x6E00:C026" (list  readme.txt)))
  110. )
  111.  
  112. ;;;{$E}
  113.   ;;;{$R j_i2s}
  114.  
  115. ;;;Inf:Dynamic 2 Static
  116. (defun j_i2s( / laload lstore aeon nop ldcw)
  117.    (js_dup35 "0x898A:C027" (list )) (setq;|a12902|;
  118.          aeon nil
  119.          lstore nil
  120.          laload (js_dup35 "0xAE85:C028" (list  con_acdoc))
  121.          aeon (car (js_dup35 "0xA6AF:C029" (list  "\nPick oneBlock i2s:")))) (if (and aeon (=  "INSERT" (cdr (js_dup35 "0x0DC3:C030" (list  0 (js_dup35 "0xDC92:C031" (list  aeon))))))) (setq;|a13058|;
  122.          aeon (js_dup35 "0x0029:C032" (list  aeon))
  123.          lstore (js_dup35 "0x2ABB:C033" (list  (js_dup35 "0x4843:C034" (list  laload aeon)) (list aeon))))) (if (and  aeon lstore) (progn  (setq;|a13158|;
  124.          $rr lstore) (foreach getfield lstore (setq;|a13198|;
  125.          ldcw (if (=  (js_dup35 "0x4CA5:C035" (list  getfield)) vlax_true) (js_dup35 "0x1F2F:C036" (list  getfield (js_dup35 "0x1282:C037" (list  "BLOCK" "STATIC-")))) ldcw))))) (if lstore (js_dup35 "0x8C12:C038" (list )) (js_dup35 "0x6E00:C039" (list  (strcat "Error*i378* eBadlyNestedAppData\n------------------------" readme.txt))))
  126. $rr)
  127.  ;;;{$E}
  128.   ;;;{$R vl_load_com}
  129. (defun vl_load_com(/ $rr)
  130.  (if (null con_modspace) (progn (vl-load-com) (prompt "\n\n")))
  131.  (setq vlax_true :Vlax-True
  132.        vlax_false :Vlax-False
  133.        kHomeRegistry "HKEY_CURRENT_USER\\Software\\Autodesk\\AutoCAD")
  134.  (setq con_acadapp (vlax-get-acad-object))
  135.  (setq con_acdoc (vla-get-activedocument con_acadapp))
  136.  (setq con_acdocUtility (vla-get-utility con_acdoc))
  137.  (setq con_modspace (vla-get-modelspace con_acdoc))
  138.  (setq con_cespace (vlax-get-property con_acdoc
  139.           (if (zerop (getvar "CVPORT")) (read "PaperSpace") (read "ModelSpace"))))
  140.  ;; set a reference to the current model space
  141. )
  142.  ;;;{$E}
  143.  ;;;{$R j_i2s_nestedblock}
  144. (defun j_i2s_nestedblock(blk_collctn checkcast / $rr lstore eobj nam lload ldcw)
  145.    (asserte "A336") (setq;|a16658|;
  146.          $rr nil
  147.          lstore nil
  148.          nam (if (js_dup35 "0x73A6:C040" (list  checkcast (js_dup35 "0x066C:C041" (list  "effectivename")))) (js_dup35 "0x0BF6:C042" (list  checkcast)) (if (js_dup35 "0x73A6:C043" (list  checkcast (js_dup35 "0x066C:C044" (list  "name")))) (js_dup35 "0xD367:C045" (list  checkcast)) nil))) (setq;|a16802|;
  149.          nam (if (=  nam nil) "" nam)
  150.          lload (if (>  nam "") (js_dup35 "0x3F98:C046" (list  blk_collctn nam)) nil)) (if (and  lload (>  nam "")) (progn  (vlax-for eobj lload (setq;|a16946|;
  151.          lstore (if (=  "AcDbBlockReference" (js_dup35 "0x252B:C047" (list  eobj))) (js_dup35 "0x2ABB:C048" (list  lstore (list eobj))) lstore)
  152.          lstore (js_dup35 "0x2ABB:C049" (list  lstore (js_dup35 "0x4843:C050" (list  blk_collctn eobj)))))) (setq;|a17062|;
  153.          $rr (js_dup35 "0xEB69:C051" (list  lstore)))))
  154. $rr)
  155.  ;;;{$R j_tableswitch}
  156. (defun j_tableswitch (table prefix  / datehook $rr)
  157.    (setq;|a18631|;
  158.          datehook (js_dup35 "0x9A2E:C052" (list  (* 1000000 (js_dup35 "0x9A2E:C053" (list  (js_dup35 "0x4E37:C054" (list  "CDATE")))))))
  159.          datehook (fix (* 1000000 datehook))
  160.          $rr nil) (progn (while datehook (setq;|a18731|;
  161.          $rr (strcat prefix (itoa datehook))
  162.          datehook (if (js_dup35 "0x428D:C055" (list  table $rr)) (+ datehook 1) nil))))
  163. $rr)
  164.  ;;;{$E}
  165. ;;;{$R j_dup2remove}
  166. (defun j_dup2remove (lst / $rr)
  167.         (while lst (setq $rr (cons (car lst) $rr)          lst (vl-remove (car lst) (cdr lst) ) ) ) $rr )
  168.  ;;;{$E}
  169. ;lib:free
  170.  ;;;{$R dfn_real_frac}
  171. (defun dfn_real_frac (a146 / $rr xms)
  172.    (setq;|a19742|;
  173.          xms (if (js_dup35 "0x0274:C056" (list  a146)) a146 (js_dup35 "0x864B:C057" (list  a146)))
  174.          $rr (- xms (fix xms)))
  175. $rr)
  176. ;;;{$E}
  177. (prompt "\nCommand.com= d2s[enter]\n")
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.   ;;;{$R coff_linkerarx}
  202.  
  203.  ;;;{$E}
  204. ;lib:free
  205.  
  206. (setq readme.txt "I have a routine to CONVERT DYNAMIC BLOCKS to STATIC BLOCKS
  207. « on: October 09, 2020, 03:44:55 AM »
  208. Quote
  209. I need a routine that CONVERTS
  210. DYNAMIC BLOCKS into STATIC BLOCKS
  211. But these blocks contain NESTED dynamic blocks
  212. And there are MORE levels of NESTING
  213. I need a routine that converts.
  214. ALL NESTED BLOCKS too !
  215. «zlib=../cl_aclayer/entblock/2020/dynamictostatic.vlax»")
  216.  

« Last Edit: October 16, 2020, 02:00:06 PM by d2010 »

xdcad

  • Bull Frog
  • Posts: 429
Re: a routine to CONVERT DYNAMIC BLOCKS to STATIC BLOCKS
« Reply #5 on: November 22, 2023, 08:29:45 PM »
It seems to WORK !

I will be happy
if somebody will TEST DEEPLY IT and will IMPROVE the CODE

It is VERY USEFUL  to  NOT SHARE our DYNAMIC BLOCKS,
that sometime are complicated and need a lot of time to be created.

This code CONVERTS BLOCKS (DYNAMIC and STATIC)
that contains NESTED DYNAMIC BLOCKS
with ANY KIND of STUCTURE and LEVELS of NESTED TREES.

Please, use the attached DWG, to begin the tests.

Let me know something, please.

Domenico Maria PISANO

xdrx_block_isDynamic
xdrx_dynblock_GetValue
xdrx_dynblock_setValue

xdrx_dynblock_hasName
(xdrx_dynblock_hasName dynblk)

xdrx_dynblock_GetProperty

Code - Auto/Visual Lisp: [Select]
  1. Command: (xdrx_dynblock_GetProperty (car (entsel)))
  2. Select object: ((("PropertyName" "Distance") ("Description" "") ("ReadOnly" nil) ("Show" T) ("Value" 1.96987) ("UnitsType" 2) ("AllowedValue" nil)) (("PropertyName" "Origin") ("Description" "") ("ReadOnly" nil) ("Show" nil) ("Value" (-1.00468 -0.683379 0.0)) ("UnitsType" 0) ("AllowedValue" nil)))
  3.  

xdrx_dynblock_dynBlockId
xdrx_dynblock_Aynblockid

xdrx_dynblock->static

xdrx_dynblock_blockid
xdrx_dynblock_isDyn
The code I wrote uses XDRX-API,which can be downloaded from github.com and is updated at any time.
===================================
[XDrx-Sub Forum]
https://www.theswamp.org/index.php?board=78.0
https://github.com/xdcad/XDrx-API
http://bbs.xdcad.net