Author Topic: Help: Insert two blocks in the same time  (Read 1624 times)

0 Members and 1 Guest are viewing this topic.

mhy3sx

  • Newt
  • Posts: 120
Help: Insert two blocks in the same time
« on: March 27, 2023, 03:46:24 AM »
Hi, I am writing a lisp to insert two attribute blocks in the same time. The problem is that insert only the first block.

Code - Auto/Visual Lisp: [Select]
  1. (Defun c:test ( / scl scl1 pt1 pt2 ang an )
  2.  (command "_layer" "_m" "SYMBOLS-2D-SECTIONMARKS" "_c" "90" "" "")
  3.  (setq scl 1)
  4.  (setq scl1 (* scl 1))
  5.   (setq pt1 (getpoint "\nPick 2 Points")
  6.         pt2 (getpoint pt1)
  7.         ang (angle pt1 pt2)
  8.         an  (angle pt2 pt1)
  9.   )  
  10.  (setvar "attdia" 1)
  11.  (command "insert" "c:\\blocks\\blk1.dwg" pt1 scl1 scl1 (angtos (+ (/ pi 2) ang)))
  12.  (command "insert" "c:\\blocks\\blk2.dwg" pt2 scl1 scl1 (angtos (+ (/ pi 2) an)))
  13.  (setvar "attdia" 0)
  14.  (command "setvar" "clayer" "0")
  15. )
  16.  

Can any one help.

Thanks

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Help: Insert two blocks in the same time
« Reply #1 on: March 27, 2023, 10:40:25 AM »
AFAIK, you should hardcode textstrings for each attribute at the end of _.INSERT line... And for reliable way of doing it I'd add after each (command "_.INSERT"...) this snippet :

Code: [Select]
(while (< 0 (getvar (quote cmdactive)))
  (command "")
)

BTW. Remove (setvar 'attdia 0/1)...
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Insert two blocks in the same time
« Reply #2 on: March 27, 2023, 11:26:09 AM »
Hi ribarm. I use

Code: [Select]
(setvar "attdia" 0)
 (setvar "attdia" 1)

because the block I use are attribiutes. Have a tag "TOMH" with the name of the section A-A or B-B etc . The tag is the same for blk1.dwg and blk2.dwg .Is any way to insert the same time the two blocks and fill the tag "TOMH" with the name of the section ?

Code - Auto/Visual Lisp: [Select]
  1. (Defun c:test ( / scl scl1 pt1 pt2 ang an )
  2.  (command "_layer" "_m" "SYMBOLS-2D-SECTIONMARKS" "_c" "90" "" "")
  3.  (setq scl 1)
  4.  (setq scl1 (* scl 1))
  5.   (setq pt1 (getpoint "\nSpecify first point: ")
  6.           pt2 (getpoint pt1 "\nSpecify second point:")
  7.           ang (angle pt1 pt2)
  8.   )
  9.  (setvar "attdia" 1)
  10.  (command "insert" "c:\\blocks\\blk1.dwg" pt1 scl1 scl1 (angtos (+ (/ pi 2) ang)))
  11.  (command "insert" "c:\\blocks\\blk2.dwg" pt2 scl1 scl1 (angtos (+ (/ pi 2) ang)))
  12.  (setvar "attdia" 0)
  13.  (command "setvar" "clayer" "0")
  14. )
  15.  

Thanks


Now is working but I have to give two times the name of the section
« Last Edit: March 27, 2023, 11:29:19 AM by mhy3sx »

ribarm

  • Gator
  • Posts: 3274
  • Marko Ribar, architect
Re: Help: Insert two blocks in the same time
« Reply #3 on: March 27, 2023, 11:37:39 AM »
Have you tried :

Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / scl scl1 pt1 pt2 ang an )
  2.   (command "_.layer" "_m" "SYMBOLS-2D-SECTIONMARKS" "_c" "90")
  3.   (while (< 0 (getvar (quote cmdactive)))
  4.     (command "")
  5.   )
  6.   (setq scl 1)
  7.   (setq scl1 (* scl 1))
  8.   (setq pt1 (getpoint "\nSpecify first point: ")
  9.         pt2 (getpoint pt1 "\nSpecify second point:")
  10.         ang (angle pt1 pt2)
  11.   )
  12.   (command "_.insert" "c:\\blocks\\blk1.dwg" pt1 scl1 scl1 (angtos (+ (/ pi 2) ang)) "A-A")
  13.   (while (< 0 (getvar (quote cmdactive)))
  14.     (command "")
  15.   )
  16.   (command "_.insert" "c:\\blocks\\blk2.dwg" pt2 scl1 scl1 (angtos (+ (/ pi 2) ang)) "B-B")
  17.   (while (< 0 (getvar (quote cmdactive)))
  18.     (command "")
  19.   )
  20.   (setvar (quote clayer) "0")
  21.   (princ)
  22. )
  23.  
Marko Ribar, d.i.a. (graduated engineer of architecture)

:)

M.R. on Youtube

Crank

  • Water Moccasin
  • Posts: 1503
Re: Help: Insert two blocks in the same time
« Reply #4 on: March 27, 2023, 11:40:07 AM »
I don't think ATTDIA is a problem. You should look at the  ATTREQ variable.

You are loading the block every time. Better check if it's already present:
Code: [Select]
(if (not (tblsearch "BLOCK" "blk2"))(progn
(command-s ".insert" "blk1=c:\\blocks\\blk1.dwg" (command))
(command-s ".insert" "blk2=c:\\blocks\\blk2.dwg" (command))
))
Vault Professional 2023     +     AEC Collection

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Insert two blocks in the same time
« Reply #5 on: March 27, 2023, 01:04:43 PM »
Thanks

BIGAL

  • Swamp Rat
  • Posts: 1414
  • 40 + years of using Autocad
Re: Help: Insert two blocks in the same time
« Reply #6 on: March 27, 2023, 06:22:51 PM »
If like us and have lots of blocks then add the directory to your support paths, then can insert Blk1 no need for path.
A man who never made a mistake never made anything

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Insert two blocks in the same time
« Reply #7 on: April 06, 2023, 04:08:30 AM »
This works until today. Today not inset the given name (num). Any ideas?


Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / scl scl1 pt1 pt2 ang klim num)
  2.  (setq scl 1)
  3.  (setq scl1 (* scl 1))
  4.   (setq pt1 (getpoint "\nSpecify first point: ")
  5.         pt2 (getpoint pt1 "\nSpecify second point:")
  6.         num (getstring "\n Givethe name of the section: ")
  7.         ang (angle pt1 pt2)
  8.  )
  9.  (command "_layer" "_m" "SYMBOLS-2D-SECTIONMARKS" "_c" "90" "" "")
  10.  (command "insert" "c:\\blocks\\blk2.dwg" pt1 scl1 scl1 (angtos (+ (/ pi 2) ang)) num "")
  11.  (command "insert" "c:\\blocks\\blk2.dwg" pt2 scl1 scl1 (angtos (+ (/ pi 2) ang)) num "")
  12.  (mapcar 'setvar '("clayer" "cecolor" "celtype" "celweight") (list "0" "BYLAYER" "BYLAYER" -1))
  13. )
  14.  

Thanks

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Insert two blocks in the same time
« Reply #8 on: April 06, 2023, 04:34:08 PM »
Any ideas ?

Thanks

57gmc

  • Bull Frog
  • Posts: 366
Re: Help: Insert two blocks in the same time
« Reply #9 on: April 06, 2023, 05:36:40 PM »
Most of the time, just saying "it doesn't work" doesn't provide any information to let people help you. Describe the problem, e.g. any errors or output.

Since you just prompt the user for a string, most likely you num argument. Maybe the file got moved?

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2139
  • class keyThumper<T>:ILazy<T>
Re: Help: Insert two blocks in the same time
« Reply #10 on: April 06, 2023, 11:16:33 PM »
If I understand pronerly,
perhaps try something like :

Code - Auto/Visual Lisp: [Select]
  1. (if (setq blockPath (findfile "c:\\blocks\\blk2.dwg") )
  2.     (progn
  3.         (command "insert" "blockpath // . . . etc    )
  4.        (command "insert" "blockpath // . . . etc    )
  5.     )
  6.     ;;else
  7.     (prompt "Error . . . " )
  8. )
  9. (mapcar 'setvar  // . . .

alternative:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq blockPath (findtrustedfile "blk2.dwg") //. . .
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Insert two blocks in the same time
« Reply #11 on: April 07, 2023, 04:18:54 AM »
Let me explain again the problem

I have this code to insert section mark in the drawing

Code - Auto/Visual Lisp: [Select]
  1.     (defun c:test ( / scl scl1 pt1 pt2 ang klim num)
  2.      (setq scl 1)
  3.      (setq scl1 (* scl 1))
  4.       (setq pt1 (getpoint "\nSpecify first point: ")
  5.             pt2 (getpoint pt1 "\nSpecify second point:")
  6.             num (getstring "\n Givethe name of the section: ")
  7.             ang (angle pt1 pt2)
  8.      )
  9.      (command "_layer" "_m" "SYMBOLS-2D-SECTIONMARKS" "_c" "90" "" "")
  10.      (command "insert" "c:\\blocks\\blk2.dwg" pt1 scl1 scl1 (angtos (+ (/ pi 2) ang)) num "")
  11.      (command "insert" "c:\\blocks\\blk2.dwg" pt2 scl1 scl1 (angtos (+ (/ pi 2) ang)) num "")
  12.      (mapcar 'setvar '("clayer" "cecolor" "celtype" "celweight") (list "0" "BYLAYER" "BYLAYER" -1))
  13.     )
  14.      
  15.  


The block insert in the correct possition. Is OK

The block are attribiute and  have a tag "TOMH" with the name of the section. So I add this line to give the name of the section A or B or C  etc

Code - Auto/Visual Lisp: [Select]
  1.             num (getstring "\n Givethe name of the section: ")
  2.  

Then I add this lines to insert the block and fill the tag "TOMH"  with num


Code - Auto/Visual Lisp: [Select]
  1.      (command "insert" "c:\\blocks\\blk2.dwg" pt1 scl1 scl1 (angtos (+ (/ pi 2) ang)) num "")
  2.      (command "insert" "c:\\blocks\\blk2.dwg" pt2 scl1 scl1 (angtos (+ (/ pi 2) ang)) num "")
  3.  

From yesterday stop filling the tag "TOMH" with the num.

Can any one thell me if  missing something in the code ?

Thanks

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Insert two blocks in the same time
« Reply #12 on: April 11, 2023, 03:42:01 PM »
Any ideas?

Thanks

57gmc

  • Bull Frog
  • Posts: 366
Re: Help: Insert two blocks in the same time
« Reply #13 on: April 11, 2023, 06:29:22 PM »
I would suggest uploading a sample dwg with blk1 and blk2 in it so your code can be tested.

mhy3sx

  • Newt
  • Posts: 120
Re: Help: Insert two blocks in the same time
« Reply #14 on: April 12, 2023, 02:44:45 AM »
Hi 57gmc, I upload the block I use.

Thanks