Require macros

Require macros

Anonymous
Not applicable
1,156 Views
5 Replies
Message 1 of 6

Require macros

Anonymous
Not applicable

In attached drawing quantity of symbol ABC & XYZ is changing. Example- suppose in case (1) i want 3 numbers of ABC symbol & 4 numbers of XYZ symbol then my drawing should be like first LEFT block will come after that in centre of that 4 numbers of ABC block will come after that 4 numbers of XYZ block will come. And at the last of all XYZ block SKW block will come. At last RIGHT block will come.

Suppose ABC block quantity is zero then after LEFT block XYZ block will come then SKW & RIGHT block.

And suppose XYZ block quantity is zero then LEFT block then ABC block & then direct RIGHT block (no SKW block because it only at last of XYZ block).

I have prepared the separate WBLOCK for LEFT, ABC, XYZ, SKW & RIGHT & prepared below macros but it is only for 1 ABC & 1 XYZ. I want it will change as per the XYZ & ABC quantity.)

 

(defun dtr(d)
(/(* pi d)180.0))
;********************************************

(defun c:DIN()
(setq p (getpoint "Enter the point"))
(Setq r (getint "\n Enter number of Relays:"))
(Setq P1 (polar P (dtr 0) 1.2))
(Setq P2 (polar P1 (dtr 0) 0.197))
(command "insert" ("d:\\data\\C DRIVE\\DRIVE\\tool\\DLEFT")p 1 1 0)
(command "insert" ("d:\\data\\C DRIVE\\DRIVE\\tool\\RELAY")p 1 1 0)
(command "insert" ("d:\\data\\C DRIVE\\DRIVE\\tool\\TERMINALF")p1 1 1 0)
(command "insert" ("d:\\data\\C DRIVE\\DRIVE\\tool\\DRIGHT")p2 1 1 0)
)

0 Likes
Accepted solutions (1)
1,157 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant

[The word "macro" has a specific meaning in AutoCAD, and this isn't one.]

 

[There's no need for a (dtr) function when all you use it for is 0 degrees -- (dtr 0) is just 0.]

 

[Don't put the Block name in parentheses.  In fact, I would just put that file path in the Support File Search Path list, and just use the Block names without the path, to save code and so that it doesn't have to reach out to an external drawing file every time, after one has already been Inserted and the Block definition is in the drawing.]

 

You would obviously need to ask the User for the number of each type, something like this [and I'm using the Block names in your code, not in your description or the wacky PasteBlock-generated ones in the drawing, plus adding in something for the SKW if that's the right Block name].  Untested:

 

(defun c:DIN (/ p r# t#)
  (setq
    p (getpoint "\nEnter the point: ")
    r# (getint "\nNumber of RELAYs: ")
    t# (getint "\nNumber of TERMINALs: ")
  ); setq
  (command "_.insert" "DLEFT" p "" "" "")
  (repeat r# ; [none if r# = 0]
    (command "_.insert" "RELAY" p "" "" "")
    (setq p (polar p 0 1.2)); move Insertion point over
  ); repeat
  (repeat t# ; [none if t# = 0]
    (command "_.insert" "TERMINAL" p "" "" "")
    (setq p (polar p 0 0.197)); move Insertion point over
  ); repeat
  (if (> t# 0); only if there are any TERMINAL Block(s)
    (progn ; then
      (command "_.insert" "SKW" p "" "" ""); if that's the right name
      (setq p (polar p 0 0.058)); move Insertion point over
    ); progn
  ); if
  (command "_.insert" "DRIGHT" p "" "" "")
); defun

 

Kent Cooper, AIA
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks for reply! It works but if r# is 3 then all 3 blocks are overlap. Actually after the DLEFT symbol 1st RELAy will come. 2nd RELAY symbol will next to the 1st RELAY symbols's right most center point. likewise all symbols are required.

0 Likes
Message 4 of 6

Kent1Cooper
Consultant
Consultant

@Anonymous wrote:

... if r# is 3 then all 3 blocks are overlap. ....


It does not do that for me.  Do you have any running Object Snap mode(s) on?  Turn Osnap off and try again, and if that fixes it, put "_none" into each Insert command before the 'p' insertion-point variable:

 

(command "_.insert" "RELAY" "_none" p "" "" "")

 

and similarly in the others.

Kent Cooper, AIA
0 Likes
Message 5 of 6

Anonymous
Not applicable

How to Load file path in the Support File Search Path list. I am using AutoCAD 2015. Kindly advise. I search in Manage-Applications. but it is not there.

0 Likes
Message 6 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

How to Load file path in the Support File Search Path list. ....


OPTIONS command, Files tab, see image:

 

AddPath.png

Kent Cooper, AIA
0 Likes