Programming script to find out drawing extents and/or scale

Programming script to find out drawing extents and/or scale

Anonymous
Not applicable
1,358 Views
7 Replies
Message 1 of 8

Programming script to find out drawing extents and/or scale

Anonymous
Not applicable

Hi all. I'm new to the forum, and actually using AutoCad extensively for the first time. I've been tasked with a simple mission: to find an object in a drawing and replace it with another one... On 150 different DWGs.

 

Luckily, the original object is in the same position in all drawings, and the new object is the same for all of them too, so I downloaded ScriptPro and came up with the simple SCR file. Then I noticed the drawings are in different scales. 

 

So I've spent some hours looking all over the web for some command/routine to find out the extension in X/Y of my drawings and being able to scale the object-to-insert accordingly. My search has turned up nothing so far.

 

So I've come to the forums. Short of learning to program in LISP, is there any other way to figure this out?

 

I appreciate the advice.

0 Likes
Accepted solutions (1)
1,359 Views
7 Replies
Replies (7)
Message 2 of 8

maratovich
Advisor
Advisor

Tip one - attach an example of your .dwg file, specify what you need to find and what to replace.

 

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 3 of 8

Anonymous
Not applicable

Can't attach the original since it's non-public IP. Find an example sketch attached.

0 Likes
Message 4 of 8

maratovich
Advisor
Advisor

1. Your objects consist of two elements (a circle and a hatch). Are they always like this or is it a block in the original?
2. The object to replace the rectangle is rotated (strange)
3. The left indent is different, but the indent on the right was checked? Maybe the right indent the same?
4. Is it a title block frame?
5. Is this all in Model?
6. Frame one in each file?
7. Is there only one replacement object in the drawing or many similar?

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 5 of 8

Anonymous
Not applicable

@maratovich wrote:

1. Your objects consist of two elements (a circle and a hatch). Are they always like this or is it a block in the original?
2. The object to replace the rectangle is rotated (strange)
3. The left indent is different, but the indent on the right was checked? Maybe the right indent the same?
4. Is it a title block frame?
5. Is this all in Model?
6. Frame one in each file?
7. Is there only one replacement object in the drawing or many similar?


1. It's a sketch,  so in the real case I need to take away a text and insert some text which gets updated each time the file is opened; but it could change in future iterations. The insert I can do with a simple paste. However, the nature of the object to be erased and pasted I believe is independent of the what I need to accomplish here, which would be to script some code which gives me back the size of the drawing. I've already managed the code to erase/paste.

2. The rectangle is just an example. Don't pay mind to it.

3. See number 2.

4. The original frame is indeed a block.

5. Yes, the original drafter had the whole drawing in model space. He used no layouts.

6. The frame is similar in all drawings, not exactly the same. There are three or four different blocks for frames in the pack, but the object I want to erase/paste are always proportionately placed in the same place relative to 0,0.

7. Right now there is only one replacement object in each drawing, but seeing how often such replacements are done in the office the might be any number of replacements in the future.

 

Please find below the code I'm using. It's fairly simple and would work flawlessly except for the fact that each dwg is scaled differently. This is why my problem right now is getting some code to tell me what scale/size each drawing is.

_.ERASE W 37'-0-3/8",2'-8-7/16" 121'-2-1/16",1'-7-1/16"

_.PASTECLIP 37'-1-13/16",1'-9-1/8"
ZOOM E
QSAVE

Thanks for replying man!

 

 

0 Likes
Message 6 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

.... Then I noticed the drawings are in different scales. .... to find out the extension in X/Y of my drawings and being able to scale the object-to-insert accordingly. My search has turned up nothing so far.

.....


 

AutoLisp can find that out, assuming there isn't anything drawn outside the perimeter outline, using the EXTMIN and EXTMAX System Variables.

 

(setq dwgsize (mapcar '- (getvar 'extmax) (getvar 'extmin)))

 

In your sample sketch drawing, that returns:

(34.7374 8.07021 0.0)

 

The first number is the extent in the X direction, the second the extent in the Y direction.  [But it's the total extents of that drawing, including your Dimension/notes.]  From comparing those to the result in your first drawing, you should be able to calculate relative scale.  If the proportions of the outline are always the same, you'd need to use only one of those numbers.

Kent Cooper, AIA
Message 7 of 8

maratovich
Advisor
Advisor

You have confused us.
Your example is not true?
Everything depends on how the title block is made.
Attach the exact sample that you have.
We are not psychics, we can not guess.

---------------------------------------------------------------------
Software development
Automatic creation layouts and viewport. Batch printing drawings from model.
www.kdmsoft.net
0 Likes
Message 8 of 8

Anonymous
Not applicable
@Kent1Cooper wrote:

 

AutoLisp can find that out, assuming there isn't anything drawn outside the perimeter outline, using the EXTMIN and EXTMAX System Variables.

 

(setq dwgsize (mapcar '- (getvar 'extmax) (getvar 'extmin)))

 

In your sample sketch drawing, that returns:

(34.7374 8.07021 0.0)

 

The first number is the extent in the X direction, the second the extent in the Y direction.  [But it's the total extents of that drawing, including your Dimension/notes.]  From comparing those to the result in your first drawing, you should be able to calculate relative scale.  If the proportions of the outline are always the same, you'd need to use only one of those numbers.


Perfect! This is exactly what I needed. Thanks!

0 Likes