Author Topic: How to Store Blocks  (Read 768 times)

0 Members and 1 Guest are viewing this topic.

mailmaverick

  • Bull Frog
  • Posts: 473
How to Store Blocks
« on: July 27, 2021, 02:09:14 AM »
Hi,

I have few standard blocks in an AutoCAD file which can be added through a LISP.

Instead of keeping the blocks in an AutoCAD file, is it possible to store them in a DLL or any other hidden way something like that which can be added only through a LISP ?

tombu

  • Bull Frog
  • Posts: 246
  • ByLayer=>Not0
Re: How to Store Blocks
« Reply #1 on: July 27, 2021, 11:51:23 AM »
Closest thing I can think of would be a Tool Palette. Why would you want to hide them anyway?
Tom Beauford P.S.M.
Leon County FL Public Works - Windows 7 64 bit AutoCAD Civil 3D

57gmc

  • Newt
  • Posts: 117
Re: How to Store Blocks
« Reply #2 on: July 27, 2021, 03:39:45 PM »
If you're trying to 'protect' them, anyone with access to the dwg can WBLOCK the block to a file.

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9718
Re: How to Store Blocks
« Reply #3 on: July 27, 2021, 03:46:25 PM »
Idea: a dxf file (or even as DWG but...)?
You could save the file as anything you want (dxf can be ASCII) and just manipulate the file (name) as necessary for insert.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

steve.carson

  • Newt
  • Posts: 88
Re: How to Store Blocks
« Reply #4 on: July 27, 2021, 05:15:55 PM »
Can you entmake a block (and then the block reference)? If it's possible then your lisp can just do that and you won't have any external file at all.

Grrr1337

  • Swamp Rat
  • Posts: 770
Re: How to Store Blocks
« Reply #5 on: July 27, 2021, 05:19:41 PM »
Heres an example I did back in the time:
Code - Auto/Visual Lisp: [Select]
  1. ;|
  2. (
  3.   (lambda ( p aL )
  4.     (mapcar '(lambda (x) (apply 'InsertAntetkaCell (cons (setq p (polar p (* -0.5 PI) 60.)) x))) aL)
  5.   ); lambda
  6.   (getpoint)
  7.   '(("A1" "A2")("B1" "B2")("C1" "C2")("D1" "D2"))
  8. )
  9. |;
  10. ; (InsertAntetkaCell (getpoint) "Hello" "World")
  11. (defun InsertAntetkaCell ( p tagt tagv / o r )
  12.  
  13.   ; RetVal = object.InsertBlock(InsertionPoint, Name [, Xscale [, Yscale [, ZScale [, Rotation [, Password]]]]])
  14.  
  15.   (or (tblsearch "BLOCK" "Antetka_Cell") ; The original block was exploded, then was used a test subfoo from (DescribeCurve) to get the list of enx-s, then the following gc's were removed: (-1 5 330)
  16.     (mapcar 'entmake
  17.       (append
  18.         '(
  19.           ( ; Required ; _$ (entget (tblobjname "STYLE" "dims") '("*")) ; renamed from "dims" to "AntCell"
  20.             (0 . "STYLE") (100 . "AcDbSymbolTableRecord") (100 . "AcDbTextStyleTableRecord") (2 . "AntCell") (70 . 0)
  21.             (40 . 0.0) (41 . 0.8) (50 . 0.0) (71 . 0) (42 . 100.0) (3 . "Arial_1.ttf") (4 . "") (-3 ("ACAD" (1000 . "Arial") (1071 . 34)))
  22.           )
  23.         )
  24.         '(((0 . "BLOCK") (100 . "AcDbEntity") (67 . 0) (8 . "0") (100 . "AcDbBlockReference") (66 . 1) (2 . "Antetka_Cell") (10 0.0 0.0 0.0) (70 . 2)))
  25.         '(
  26.           ( (0 . "ATTDEF")(100 . "AcDbEntity")(67 . 0)(410 . "Model")(8 . "0")(62 . 251)(100 . "AcDbText")(10 10.0001 -39.3753 0.0)(40 . 18.75)
  27.             (1 . "DefaultT")(50 . 3.25917e-67)(41 . 0.8)(51 . 0.0)(7 . "AntCell")(71 . 0)(72 . 0)(11 10.0001 -20.6253 0.0)(210 0.0 0.0 1.0)
  28.             (100 . "AcDbAttributeDefinition")(280 . 0)(3 . "PromptT")(2 . "TAGT")(70 . 0)(73 . 0)(74 . 3)(280 . 1)
  29.           )
  30.           ( (0 . "ATTDEF")(100 . "AcDbEntity")(67 . 0)(410 . "Model")(8 . "0")(62 . 251)(100 . "AcDbText")(10 331.473 -39.375 0.0)(40 . 18.75)
  31.             (1 . "DefaultV")(50 . 3.25917e-67)(41 . 0.8)(51 . 0.0)(7 . "AntCell")(71 . 0)(72 . 1)(11 360.0 -30.0 0.0)(210 0.0 0.0 1.0)
  32.             (100 . "AcDbAttributeDefinition")(280 . 0)(3 . "PromptV")(2 . "TAGV")(70 . 0)(73 . 0)(74 . 2)(280 . 1)
  33.           )
  34.           ( (0 . "LWPOLYLINE")(100 . "AcDbEntity")(67 . 0)(410 . "Model")(8 . "0")(100 . "AcDbPolyline")(90 . 4)(70 . 1)(43 . 0.0)(38 . 0.0)(39 . 0.0)
  35.             (10 240.0 0.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)  (10 480.0 0.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)
  36.             (10 480.0 -60.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)  (10 240.0 -60.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)
  37.             (210 0.0 0.0 1.0)
  38.           )
  39.           ( (0 . "LWPOLYLINE")(100 . "AcDbEntity")(67 . 0)(410 . "Model")(8 . "0")(100 . "AcDbPolyline")(90 . 4)(70 . 1)(43 . 0.0)(38 . 0.0)(39 . 0.0)
  40.             (10 0.0 0.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)  (10 240.0 0.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)
  41.             (10 240.0 -60.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)  (10 0.0 -60.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)
  42.             (210 0.0 0.0 1.0)
  43.           )
  44.           ( (0 . "LWPOLYLINE")(100 . "AcDbEntity")(67 . 0)(410 . "Model")(8 . "0")(100 . "AcDbPolyline")(90 . 4)(70 . 1)(43 . 0.0)(38 . 0.0)(39 . 0.0)
  45.             (10 480.0 0.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)  (10 750.0 0.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)
  46.             (10 750.0 -60.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)  (10 480.0 -60.0)(40 . 0.0)(41 . 0.0)(42 . 0.0)(91 . 0)
  47.             (210 0.0 0.0 1.0)
  48.           )
  49.         ); list
  50.         '(((0 . "ENDBLK") (100 . "AcDbBlockEnd") (8 . "0")))
  51.       ); append
  52.     ); mapcar
  53.   ); or
  54.  
  55.   (and
  56.     (tblsearch "BLOCK" "Antetka_Cell")
  57.     (setq o (vlax-invoke (vla-get-Block (vla-get-ActiveLayout (vla-get-ActiveDocument (vlax-get-acad-object)))) 'InsertBlock p "Antetka_Cell" 1. 1. 1. 0.))
  58.     (mapcar 'vla-put-TextString (vlax-invoke o 'GetAttributes) (list tagt tagv))
  59.     (setq r o)
  60.   ); and
  61.   r
  62. ); defun InsertAntetkaCell

I was manually creating the block definition I wanted, then via LISP iterated through it and stored for each item the dxf data,
then manually cleaned it a bit and hardcoded it between (0 . "BLOCK") and (0 . "ENDBLK") dxfs.
Although it works for attributed blocks, this method wouldn't be possible for dynamic blocks (or atleast very hard to program).
For dynamic blocks I would Save the Block as a Drawing File, encode/decode the Stream of the dwg file or hardcode it into the .lsp code (but it may become quite lengthy - several kBs).
(apply ''((a b c)(a b c))
  '(
    (( f L ) (apply 'strcat (f L)))
    (( L ) (if L (cons (chr (car L)) (f (cdr L)))))
    (72 101 108 108 111 32 87 111 114 108 100)
  )
)

Lee Mac

  • Seagull
  • Posts: 12514
  • London, England
Re: How to Store Blocks
« Reply #6 on: July 27, 2021, 05:46:17 PM »
Here's a similar thread which may be of interest.

It's Alive!

  • Retired
  • Needs a day job
  • Posts: 7096
  • AKA Daniel
Re: How to Store Blocks
« Reply #7 on: July 28, 2021, 04:33:29 AM »
maybe just change the file extension and still use a .DWG?

edit. also, you may be able store them in a database as a blob type.
« Last Edit: July 28, 2021, 04:37:15 AM by It's Alive! »
Retired

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9718
Re: How to Store Blocks
« Reply #8 on: July 28, 2021, 08:04:16 AM »
maybe just change the file extension and still use a .DWG?

edit. also, you may be able store them in a database as a blob type.

I was thinking the same thing but I thought a ASCII dxf would allow the chance for some adjustments. I like the database idea; maybe even store/build the block from all the necessary separate pieces on a ad hoc basis.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

mailmaverick

  • Bull Frog
  • Posts: 473
Re: How to Store Blocks
« Reply #9 on: August 06, 2021, 06:12:03 AM »
maybe just change the file extension and still use a .DWG?

edit. also, you may be able store them in a database as a blob type.

What is the meaning of "store in a database as a blob type" ? How to do that ?

PS : I am talking about Block Definitions and not Block Reference. I mean I have few standard block definitions. How do I share it to anyone else so that he can add a Block Reference only through my LISP ?
« Last Edit: August 06, 2021, 06:53:45 AM by mailmaverick »

ribarm

  • Gator
  • Posts: 2527
  • Marko Ribar, architect
Re: How to Store Blocks
« Reply #10 on: August 06, 2021, 09:19:18 AM »
I think they are fooling around with you... Neither I or someone else knows what blob type is... But there are more important things than your requesting issue... To make someone use your definitions, you must share them in a file - DWG or hardcoded LSP if you want that that way and you must accept the fact that user(s) have freedom to do what he/she want(s)... No one can guarantee that their work will rely on basis you provided... When, and if, you agree to share, you can't expect that you can get much benefit on either side (you/coworkers)... Success of job done is measured only by pure practical usefulness and you must accept the fact that you can and may be used/misused by your own will - that is the risk everyone takes when acting/lurking or planing events that may or may not occur...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

John Kaul (Se7en)

  • Administrator
  • Needs a day job
  • Posts: 9718
Re: How to Store Blocks
« Reply #11 on: August 06, 2021, 10:53:01 AM »
No we are not fooling around with anyone. Dead serious.

A blob--in database language--is "Binary Large Object (Blob)".

To "store items in a database as a blob" you'd (and they as well) would need a database like SQL, SQLite, etc. To do this all via lisp you will need a way to interact with that database like: [ https://www.theswamp.org/index.php?topic=28286.msg338778#msg338778 ]. However, you can just use files in DWG or DXF format stored somewhere on the network and just insert them into the drawing via lisp.
TheSwamp.org (serving the CAD community since 2003)

Donate to TheSwamp.org

mhupp

  • Newt
  • Posts: 33
Re: How to Store Blocks
« Reply #12 on: August 06, 2021, 02:09:17 PM »
https://www.youtube.com/watch?v=fQek73drZS4&t=78s
I haven't used this at all so use at your own risk.

BIGAL

  • Swamp Rat
  • Posts: 830
  • 30 + years of using Autocad
Re: How to Store Blocks
« Reply #13 on: August 06, 2021, 08:20:41 PM »
My $0.05 once a block is in a dwg then it can be copied and saved so why hide it ? Only thing I can think of is a proxy object that is viewable, and need your app to see it. Way way above my pay rate.

Struggling to find any info about make Proxy object it will be part of SDK and Registered App.
A man who never made a mistake never made anything

d2010

  • Bull Frog
  • Posts: 202
Re: How to Store Blocks
« Reply #14 on: August 07, 2021, 06:57:00 AM »
After Three hour/s I finish,converted Automatically->Very Hard fixing the bug/s
I insert DXF into'strings into C inside Lisp,
Hi,
I have few standard blocks in an AutoCAD file which can be added through a LISP.
IBut the programe "pp_l3dxf32_pp_l3dxf32_jcpin25.lsp" , work only if
setvar"OsMode" ...183
, in all time/s, You need execute any the  function/s inside
"pp_l3dxf32_pp_l3dxf32_jcpin25.lsp
". If you set Osmode <>183, then
p_l3dxf32_pp_l3dxf32_j*.lsp Failed"

Instead of keeping the blocks in an AutoCAD file, is it possible to store them in a DLL or any other hidden way something like that which can be added only through a LISP ?
You execute the programe with Q2[enter]
You found the files.Dxf inside " cl_autovit_2020_pp_l3dxf32-vlxc.zip"
maybe just change the file extension and still use a .DWG?
edit. also, you may be able store them in a database as a blob type.
I copied the full-ascii.DXF into pp_l3dxf32_l3dxf32.lsp, before You compile to.Fas.
Best Regards..
« Last Edit: August 08, 2021, 02:43:15 AM by d2010 »