Author Topic: Insert Block  (Read 4149 times)

0 Members and 1 Guest are viewing this topic.

Fabricio28

  • Swamp Rat
  • Posts: 670
Insert Block
« on: January 21, 2014, 10:57:06 AM »
Hi guys,
It is a really poor code that insert a specific block.
But the code ask me to rotate, and I don't wanna rotate the block.

Code: [Select]
(DEFUN C:NM-01() (COMMAND "layer" "s" "-TERRENO" "" "INSERT" "NM-JANEIRO" PAUSE  "" "" ))
Anybody Can help me, please?
« Last Edit: January 21, 2014, 11:25:20 AM by FABRICIO28 »

hmspe

  • Bull Frog
  • Posts: 367
Re: Insert Block
« Reply #1 on: January 21, 2014, 11:29:28 AM »
The simple fix is
Code: [Select]
(DEFUN C:NM001() (COMMAND "layer" "s" "-TERRENO" "" "INSERT" "DEAP-NM" PAUSE "" "" "" "" "" ))
[\code]

A better approach would be
[code]
(DEFUN C:NM001()
  (COMMAND "layer" "s" "-TERRENO" "" "INSERT" "DEAP-NM" PAUSE "X" "1." "1." "1." "0." )
  (PRINC)
)
[\code]

With the simple code the "" say to accept the default values, which could be something different from scale factors of 1.0 and rotation of 0.0. 
"Science is the belief in the ignorance of experts." - Richard Feynman

CAB

  • Global Moderator
  • Seagull
  • Posts: 10401
Re: Insert Block
« Reply #2 on: January 21, 2014, 11:31:22 AM »
Using Commands can be Version specific & may vary due to system settings.
From ACAD2006
Command: -INSERT
Enter block name or [?] <A$C3EBD06A6>: 2X END VIEW

Units: Inches   Conversion: 1.00000000
Specify insertion point or [Basepoint/Scale/X/Y/Z/Rotate/PScale/PX/PY/PZ/PRotate]:
Enter X scale factor, specify opposite corner, or [Corner/XYZ] <1>:
Enter Y scale factor <use X scale factor>:

(command "-INSERT" "DEAP-NM"   PAUSE  "" "" "")
I've reached the age where the happy hour is a nap. (°¿°)
Windows 10 core i7 4790k 4Ghz 32GB GTX 970
Please support this web site.

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Insert Block
« Reply #3 on: January 21, 2014, 11:57:12 AM »
Thank you for the quick replay,

But none of code worked   :cry:

@hmspe
Your code didn't change anything  :cry:
 the code still asking to rotate the block.

@CAB
Your code works fine!
But I need invoke a command to insert the block, because I have many blocks.
e.g
Code: [Select]
;INS NM2
(DEFUN C:NM-02() (COMMAND "layer" "s" "-TERRENO" "" "INSERT" "NM-FEVEREIRO" PAUSE  "" "" ))   
;INS NM3
(DEFUN C:NM-03() (COMMAND "layer" "s" "-TERRENO" "" "INSERT" "NM-MARÇO" PAUSE  "" "" ))

efernal

  • Bull Frog
  • Posts: 206
Re: Insert Block
« Reply #4 on: January 21, 2014, 12:27:20 PM »
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c_nm-## (layer block / p1)
  2.   (IF (TBLSEARCH "BLOCK" block)
  3.     (IF (SETQ p1 (GETPOINT (STRCAT "\n-> Insertion point for " block " : ")))
  4.       (PROGN (IF (OR (NOT cor) (/= (TYPE cor) 'int) (< cor 1) (> cor 255))
  5.                (SETQ cor 7)
  6.              )
  7.              (IF (NULL (TBLSEARCH "LAYER" layer))
  8.                (ENTMAKE (LIST '(0 . "LAYER")
  9.                               '(100 . "AcDbSymbolTableRecord")
  10.                               '(100 . "AcDbLayerTableRecord")
  11.                               (CONS 2 layer)
  12.                               '(70 . 0)
  13.                               (CONS 62 cor)
  14.                               '(6 . "Continuous")
  15.                               '(290 . 1)
  16.                               '(370 . -3)
  17.                         )
  18.                )
  19.              )
  20.              (ENTMAKE (LIST (CONS 0 "INSERT")
  21.                             (CONS 2 block) ; block name
  22.                             (CONS 8 layer) ; layer name
  23.                             (CONS 10 p1) ; insertion point
  24.                             (CONS 41 1.0) ; x scale
  25.                             (CONS 42 1.0) ; y scale
  26.                             (CONS 43 1.0) ; z scale
  27.                             (CONS 50 0.0) ; rotation angle
  28.                             (CONS 210 (LIST 0.0 0.0 1.0)) ; optional
  29.                       )
  30.              )
  31.       )
  32.       (PRINC "\n-> Insertion point was not supplied...")
  33.     )
  34.     (ALERT (STRCAT "Block " block " does not exist..."))
  35.   )
  36.   (PRINC)
  37. )
  38. (DEFUN c:nm-01 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-JANEIRO") (PRINC))
  39. (DEFUN c:nm-02 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-FEVEREIRO") (PRINC))
  40. (DEFUN c:nm-03 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-MARÇO") (PRINC))
  41. ;; Etc...
  42.  
e.fernal

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Insert Block
« Reply #5 on: January 21, 2014, 12:49:02 PM »
Excellent Mr. Efenal!!!

Thank you very much   :-D

I'd like to improve just one more thing.
The code isn't find my blocks, I have to insert manually to works properly.

The blocks aren't the DesigneCenter.
I loaded my blocks in the autocad options > support file seach path.


« Last Edit: January 21, 2014, 12:59:30 PM by FABRICIO28 »

efernal

  • Bull Frog
  • Posts: 206
Re: Insert Block
« Reply #6 on: January 21, 2014, 01:14:04 PM »
Code - Auto/Visual Lisp: [Select]
  1. (DEFUN c_nm-## (layer block / p1)
  2.   (IF (NULL (TBLSEARCH "BLOCK" block))
  3.     (IF (SETQ block (STRCAT "C:\\MY_BLOCKS\\" block ".DWG")) ; change to your path...
  4.       (COMMAND "_.-INSERT" block nil)
  5.     )
  6.   )
  7.   (IF (TBLSEARCH "BLOCK" block)
  8.     (IF (SETQ p1 (GETPOINT (STRCAT "\n-> Insertion point for " block " : ")))
  9.       (PROGN (IF (OR (NOT cor) (/= (TYPE cor) 'int) (< cor 1) (> cor 255))
  10.                (SETQ cor 7)
  11.              )
  12.              (IF (NULL (TBLSEARCH "LAYER" layer))
  13.                (ENTMAKE (LIST '(0 . "LAYER")
  14.                               '(100 . "AcDbSymbolTableRecord")
  15.                               '(100 . "AcDbLayerTableRecord")
  16.                               (CONS 2 layer)
  17.                               '(70 . 0)
  18.                               (CONS 62 cor)
  19.                               '(6 . "Continuous")
  20.                               '(290 . 1)
  21.                               '(370 . -3)
  22.                         )
  23.                )
  24.              )
  25.              (ENTMAKE (LIST (CONS 0 "INSERT")
  26.                             (CONS 2 block) ; block name
  27.                             (CONS 8 layer) ; layer name
  28.                             (CONS 10 p1) ; insertion point
  29.                             (CONS 41 1.0) ; x scale
  30.                             (CONS 42 1.0) ; y scale
  31.                             (CONS 43 1.0) ; z scale
  32.                             (CONS 50 0.0) ; rotation angle
  33.                             (CONS 210 (LIST 0.0 0.0 1.0)) ; optional
  34.                       )
  35.              )
  36.       )
  37.       (PRINC "\n-> Insertion point was not supplied...")
  38.     )
  39.     (ALERT (STRCAT "Block " block " does not exist..."))
  40.   )
  41.   (PRINC)
  42. )
  43. (DEFUN c:nm-01 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-JANEIRO") (PRINC))
  44. (DEFUN c:nm-02 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-FEVEREIRO") (PRINC))
  45. (DEFUN c:nm-03 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-MARÇO") (PRINC))
  46. ;; Etc...
  47.  
e.fernal

efernal

  • Bull Frog
  • Posts: 206
Re: Insert Block
« Reply #7 on: January 21, 2014, 01:16:22 PM »
Code - Auto/Visual Lisp: [Select]
  1. ;; OOPS...
  2. (DEFUN c_nm-## (layer block / p1 block2)
  3.   (IF (NULL (TBLSEARCH "BLOCK" block))
  4.     (IF (SETQ block2 (FINDFILE (STRCAT block ".DWG"))) ; change to your path...
  5.       (COMMAND "_.-INSERT" block2 nil)
  6.     )
  7.   )
  8.   (IF (TBLSEARCH "BLOCK" block)
  9.     (IF (SETQ p1 (GETPOINT (STRCAT "\n-> Insertion point for " block " : ")))
  10.       (PROGN (IF (OR (NOT cor) (/= (TYPE cor) 'int) (< cor 1) (> cor 255))
  11.                (SETQ cor 7)
  12.              )
  13.              (IF (NULL (TBLSEARCH "LAYER" layer))
  14.                (ENTMAKE (LIST '(0 . "LAYER")
  15.                               '(100 . "AcDbSymbolTableRecord")
  16.                               '(100 . "AcDbLayerTableRecord")
  17.                               (CONS 2 layer)
  18.                               '(70 . 0)
  19.                               (CONS 62 cor)
  20.                               '(6 . "Continuous")
  21.                               '(290 . 1)
  22.                               '(370 . -3)
  23.                         )
  24.                )
  25.              )
  26.              (ENTMAKE (LIST (CONS 0 "INSERT")
  27.                             (CONS 2 block) ; block name
  28.                             (CONS 8 layer) ; layer name
  29.                             (CONS 10 p1) ; insertion point
  30.                             (CONS 41 1.0) ; x scale
  31.                             (CONS 42 1.0) ; y scale
  32.                             (CONS 43 1.0) ; z scale
  33.                             (CONS 50 0.0) ; rotation angle
  34.                             (CONS 210 (LIST 0.0 0.0 1.0)) ; optional
  35.                       )
  36.              )
  37.       )
  38.       (PRINC "\n-> Insertion point was not supplied...")
  39.     )
  40.     (ALERT (STRCAT "Block " block " does not exist..."))
  41.   )
  42.   (PRINC)
  43. )
  44. (DEFUN c:nm-01 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-JANEIRO") (PRINC))
  45. (DEFUN c:nm-02 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-FEVEREIRO") (PRINC))
  46. (DEFUN c:nm-03 (/ cor) (SETQ cor 10) (c_nm-## "-TERRENO" "NM-MARÇO") (PRINC))
  47. ;; Etc...
  48.  
e.fernal

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Insert Block
« Reply #8 on: January 21, 2014, 02:11:43 PM »
Z:\BONUS\BLOCOS DINAMICOS\NM 2014\NM-MAIO.dwg

NM-JULHO.dwg
NM-AGOSTO.dwg

It is my path. But I have more 11 file dwg in that path.
How Can I add??

Thank in advance

efernal

  • Bull Frog
  • Posts: 206
Re: Insert Block
« Reply #9 on: January 21, 2014, 05:30:46 PM »
Code - Auto/Visual Lisp: [Select]
  1. ;; try to change to:
  2.  
  3.   (IF (NULL (TBLSEARCH "BLOCK" block))
  4.    (IF (SETQ block2 (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
  5.      (COMMAND "_.-INSERT" block2 nil)
  6.    )
  7.  )
  8.  
  9.  
e.fernal

Fabricio28

  • Swamp Rat
  • Posts: 670
THANK YOU VERY MUCH!!!!!!
« Reply #10 on: January 22, 2014, 07:02:49 AM »
Just wanna say Thank you Mr. efernal!!
(Muito Obrigado Sr. efernal!)

I really appreciated your help, wasting your precious time to help me out.
The code is amazing, worked like a charm!!!


God Bless you!!

Thank you all of you guys!!!

Fabricio28

  • Swamp Rat
  • Posts: 670
Questions
« Reply #11 on: January 22, 2014, 08:16:15 AM »
I'm having 3 problems.
1° when I load the code and trying to invoke the command, didn't find the block.
So when I put NM-FEVEREIRO-A until NM-DEZEMBRO line as a comment work fine.
2° Where Can I change the color layer to 180?
3° The block's font is substituting [simplex.shx] for [romb____.pfb].
I don't wanna do that, how can I fix it?

Thank you


Code: [Select]
(DEFUN c_nm-## (layer block / p1 block2)
  (IF (NULL (TBLSEARCH "BLOCK" block))
   (IF (SETQ NM-JANEIRO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-JANEIRO nil)
   )
   (IF (SETQ NM-FEVEREIRO-A (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-FEVEREIRO-A nil)
   )
   (IF (SETQ NM-MARÇO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-MARÇO nil)
   )
   (IF (SETQ NM-ABRIL (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-ABRIL nil)
   )
   (IF (SETQ NM-MAIO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-MAIO nil)
   )
   (IF (SETQ NM-JUNHO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-JUNHO nil)
   )
   (IF (SETQ NM-JULHO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-JULHO nil)
   )
   (IF (SETQ NM-AGOSTO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-AGOSTO nil)
   )
   (IF (SETQ NM-SETEMBRO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-SETEMBRO nil)
   )
   (IF (SETQ NM-OUTUBRO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-OUTUBRO nil)
   )
   (IF (SETQ NM-NOVEMBRO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-NOVEMBRO nil)
   )
   (IF (SETQ NM-DEZEMBRO (FINDFILE (STRCAT "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\" block ".DWG")))
     (COMMAND "_.-INSERT" NM-DEZEMBRO nil)
   )
 )
(IF (TBLSEARCH "BLOCK" block)
    (IF (SETQ p1 (GETPOINT (STRCAT "\n-> Insertion point for " block " : ")))
      (PROGN (IF (OR (NOT cor) (/= (TYPE cor) 'int) (< cor 1) (> cor 255))
               (SETQ cor 7)
             )
             (IF (NULL (TBLSEARCH "LAYER" layer))
               (ENTMAKE (LIST '(0 . "LAYER")
                              '(100 . "AcDbSymbolTableRecord")
                              '(100 . "AcDbLayerTableRecord")
                              (CONS 2 layer)
                              '(70 . 0)
                              (CONS 62 cor)
                              '(6 . "Continuous")
                              '(290 . 1)
                              '(370 . -3)
                        )
               )
             )
             (ENTMAKE (LIST (CONS 0 "INSERT")
                            (CONS 2 block) ; block name
                            (CONS 8 layer) ; layer name
                            (CONS 10 p1) ; insertion point
                            (CONS 41 1.0) ; x scale
                            (CONS 42 1.0) ; y scale
                            (CONS 43 1.0) ; z scale
                            (CONS 50 0.0) ; rotation angle
                            (CONS 210 (LIST 0.0 0.0 1.0)) ; optional
                      )
             )
      )
      (PRINC "\n-> Insertion point was not supplied...")
    )
    (ALERT (STRCAT "Block " block " does not exist..."))
  )
  (PRINC)
)
(DEFUN c:nm-01 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-JANEIRO") (PRINC))
(DEFUN c:nm-02 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-FEVEREIRO-A") (PRINC))
(DEFUN c:nm-03 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-MARÇO") (PRINC))
(DEFUN c:nm-04 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-ABRIL") (PRINC))
(DEFUN c:nm-05 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-MAIO") (PRINC))
(DEFUN c:nm-06 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-JUNHO") (PRINC))
(DEFUN c:nm-07 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-JULHO") (PRINC))
(DEFUN c:nm-08 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-AGOSTO") (PRINC))
(DEFUN c:nm-09 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-SETEMBRO") (PRINC))
(DEFUN c:nm-10 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-OUTUBRO") (PRINC))
(DEFUN c:nm-11 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-NOVEMBRO") (PRINC))
(DEFUN c:nm-12 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-DEZEMBRO") (PRINC))
« Last Edit: January 22, 2014, 08:49:07 AM by FABRICIO28 »

Fabricio28

  • Swamp Rat
  • Posts: 670
Re: Insert Block
« Reply #12 on: January 22, 2014, 10:37:32 AM »
Let me attach my block...
I have more 11 blocks like that.

Regards

efernal

  • Bull Frog
  • Posts: 206
Re: Insert Block
« Reply #13 on: January 22, 2014, 10:40:13 AM »
Code - Auto/Visual Lisp: [Select]
  1. ;; Se necessário, altere o path abaixo, mas não mexa na função c_nm-##
  2. ;; Change here, if necessary, but do not change function c_nm-##
  3. (SETQ fabricio_nm_path "Z:\\BONUS\\BLOCOS DINAMICOS\\NM 2014\\")
  4. ;; ==============================================================================
  5. ;; Por favor, não modifique a função c_nm-##
  6. ;; Please, do not  modify function C_NM-##
  7. (DEFUN c_nm-## (layer block / p1 block2)
  8.   (FOREACH x '("NM-JANEIRO"      "NM-FEVEREIRO"    "NM-MARÇO"        "NM-MARCO"
  9.                "NM-ABRIL"        "NM-MAIO"         "NM-JUNHO"        "NM-JULHO"
  10.                "NM-AGOSTO"       "NM-SETEMBRO"     "NM-OUTUBRO"      "NM-NOVEMBRO"
  11.                "NM-DEZEMBRO"
  12.               )
  13.     (IF (NULL (TBLSEARCH "BLOCK" x))
  14.       (IF (SETQ block2 (FINDFILE (STRCAT fabricio_nm_path x ".DWG")))
  15.         (COMMAND "_.-INSERT" block2 nil)
  16.       )
  17.     )
  18.   )
  19.   (IF (TBLSEARCH "BLOCK" block)
  20.     (IF (SETQ p1 (GETPOINT (STRCAT "\n-> Insertion point for " block " : ")))
  21.       (PROGN (IF (OR (NOT cor) (/= (TYPE cor) 'int) (< cor 1) (> cor 255))
  22.                (SETQ cor 7)
  23.              )
  24.              (IF (NULL (TBLSEARCH "LAYER" layer))
  25.                (ENTMAKE (LIST '(0 . "LAYER")
  26.                               '(100 . "AcDbSymbolTableRecord")
  27.                               '(100 . "AcDbLayerTableRecord")
  28.                               (CONS 2 layer)
  29.                               '(70 . 0)
  30.                               (CONS 62 cor)
  31.                               '(6 . "Continuous")
  32.                               '(290 . 1)
  33.                               '(370 . -3)
  34.                         )
  35.                )
  36.              )
  37.              (ENTMAKE (LIST (CONS 0 "INSERT")
  38.                             (CONS 2 block) ; block name
  39.                             (CONS 8 layer) ; layer name
  40.                             (CONS 10 p1) ; insertion point
  41.                             (CONS 41 1.0) ; x scale
  42.                             (CONS 42 1.0) ; y scale
  43.                             (CONS 43 1.0) ; z scale
  44.                             (CONS 50 0.0) ; rotation angle
  45.                             (CONS 210 (LIST 0.0 0.0 1.0)) ; optional
  46.                       )
  47.              )
  48.       )
  49.       (PRINC "\n-> Insertion point was not supplied...")
  50.     )
  51.     (ALERT (STRCAT "Block " block " does not exist..."))
  52.   )
  53.   (PRINC)
  54. )
  55. ;; ==============================================================================
  56. ;; ==============================================================================
  57. (DEFUN c:nm-01 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-JANEIRO") (PRINC))
  58. (DEFUN c:nm-02 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-FEVEREIRO") (PRINC))
  59. (DEFUN c:nm-03 (/ cor) (SETQ cor 180) (c_nm-## "-TERRENO" "NM-MARÇO") (PRINC))
  60. ;; insira outros comandos aqui. Siga os exemplos acima...
  61. ;; insert other commands heres. Follow example above...:
  62. ;; (DEFUN C:NM-04 (/ cor) .......
  63. ;; Etc...
  64.  
  65.  
e.fernal

Fabricio28

  • Swamp Rat
  • Posts: 670
Perfect!!!!!
« Reply #14 on: January 22, 2014, 10:55:22 AM »
Mr. E.Fernal

I have no words to say Thank you very much!!!
The code is amazing!!!

Thank you for everything.
 :-D