Jump to content

Scaling LISP - can you guys please help me tidy it up a litte...


lamensterms

Recommended Posts

Hey guys,

 

Ive just put together a little scaling LISP which allows the user to select objects (in my case its a title block for a 2D DRG) and scale them accordingly.

 

So my application is...

 

For 2D working DRGs - we have a title block inserted at whatever scale the DRG was originally created at - the user will wish to re-scale this title block... but the DIMSCALE, LTSCALE and text will need to also be scaled accordingly. We also have a field (ATTRIBUTE) within the title block which needs to note what scale the DRG is at.

 

So... i have created this routine - which does work... but i feel it requires a little too much input. Heres what is required by the user as they run this routine...

 

1. Run command. SSC

2. Select objects to scale. Title block and material list

3. Enter current scale. 50

4. Enter desired scale. 25

5. Enter scale as it currently appears in title block. 1:50

6. Enter scale as it will appear in title block. 1:25

 

As you can see - there is a bit of semi-repetition required by the user (though it is much simpler than modifying all the scale values manually).

 

I basically would like to eliminate steps 5 and 6 - have those inputs be read from steps 3 and 4 if possible.

 

It would also be fantastic if the data enter by the user in step 3 could be read automatically (maybe read it from the original DIMSCALE value - though this could be risky if the initial DIMSCALE was not set correctly).

 

Here is the code:

 

(DEFUN C:ssc ()
(setq ocmd (getvar "CMDECHO"))
(prompt "\nSelect Title Block, Mark and Material List to be re-scaled... ")
(setq sscpt1 '(0 0 0))
(setq sscsset1 (ssget))
(SETQ ssccs (getreal "\nEnter Current Scale : "))
(SETQ sscds (getreal "\nEnter Desired Scale : "))
(COMMAND "scale" sscsset1 "" sscpt1 (/ sscds ssccs))
(COMMAND "dimscale" sscds)
(COMMAND "ltscale" (* sscds 10))
(COMMAND "-style" "PDC_Prosteel" "isocp.shx" (* sscds 3.5) "1" "0" "NO" "NO")
(SETQ ssctso (getstring "\nEnter Current Scale as it appears in title block (1:5, 1:10, 1:50, etc): "))
(SETQ ssctsn (getstring "\nEnter Desired Scale as it will appear in title block: "))
(COMMAND "-attedit" "n" "n" "pdctitle" "pdcscale" "" ssctso ssctsn)
(COMMAND "graphscr")
(setvar "CMDECHO" ocmd)
(princ)
)

 

Thanks a lot for any help dudes.

Edited by lamensterms
Link to comment
Share on other sites

You can avoid prompting the user for base scale by getting this from the title block entity - since you know the relation between drawing scale and block's insertion scale you can calculate the required value. Also may be safe to filter out entities other than blocks at selection:

 

(setq sscsset1 (ssget '((0 . "INSERT"))))
(setq ssccs (cdr (assoc 41 (entget (ssname sscpt1 0)))))
(setq ssccs ([color=black]/[/color]ssccs BaseBlockScale))[color=blue]   ;add your formula here[/color]

 

After that, since you have the base scale (read), respectively target scale (input) you can convert those to strings:

 

(setq ssctso (strcat "1:" (itoa ssccs))
     ssctsn (strcat "1:" (itoa (fix sscds))))

 

This way may get rid of 3 prompts.

 

Regards,

Mircea

Link to comment
Share on other sites

Thanks a lot for the reply mircea. I'm afraid im not at my computer right now so I can't test it out.

 

Can you please help me out by inserting your code into mine? I'm not really sure where it should all go.

 

Thanks again, ill let you know if I have any luck.

Link to comment
Share on other sites

You’re welcome!

I’m sure that you will benefit more if will try to fix the code by yourself. Just do one change at a time and test the effect.

 

Regards,

Mircea

Link to comment
Share on other sites

No problem Mircea,

 

Thanks again.

 

I'll post back in a few hours and let you know how much success I have.

Link to comment
Share on other sites

Hello again,

 

So i ended up getting it to work quite well... though i havent quite been able to get the routine to read the current scale - little trickier.

 

I managed to tweak the code you gave me to read the initial inputs and compile the string (had to replace ITOA with RTOS - is that correct?).

 

One of the problems with reading the scale from the existing block is that the title block is not made up of just 1 block - it is a few different blocks, some lines, text, etc. So i will try to get the routine to read the scale from one of the blocks (select > blockname?).

 

So, with your help Mircea - i have managed to eliminate the need for steps 5 and 6... hopefully ill be able to get rid of step 3 soon too.

 

Here is the current code...

 

(DEFUN C:ssc ()
(setq ocmd (getvar "CMDECHO"))
(prompt "\nSelect Title Block, Mark and Material List to be re-scaled... ")
(setq sscpt1 '(0 0 0))
(setq sscsset1 (ssget))
(SETQ ssccs (getreal "\nEnter Current Scale : "))
(SETQ sscds (getreal "\nEnter Desired Scale : "))
(COMMAND "scale" sscsset1 "" sscpt1 (/ sscds ssccs))
(COMMAND "dimscale" sscds)
(COMMAND "ltscale" (* sscds 10))
(COMMAND "-style" "PDC_Prosteel" "isocp.shx" (* sscds 3.5) "1" "0" "NO" "NO")
(setq ssctso (strcat "1:"(rtos ssccs)))
(setq ssctsn (strcat "1:"(rtos sscds)))
(COMMAND "-attedit" "n" "n" "pdctitle" "pdcscale" "" ssctso ssctsn)
(COMMAND "graphscr")
(setvar "CMDECHO" ocmd)
(princ)
)

 

 

Thanks again.

Link to comment
Share on other sites

Can I ask a dumb question why are you not using layouts with your title block there ? draw at 1:1 plot at whatever scale you want. Its a better way to go than plotting from modelspace.

Link to comment
Share on other sites

Hi BIGAL,

 

Good question mate - the software package were using with AutoCAD was setup by another drafting office, so we are pretty much following their procedure. Its for steel detailing, a model is created in one .DWG, then the 2D DRGs are created (exported from the model) in a lot of other .DWGs. The title block is all inserted as part of the export procedure... but the scale is always set as a default (1:10). The other office scale by manually editting each setting (as listed in first post) - i figured creating a routine to modify all settings at once would be good. And thanks to the help of Mircea... thats what i have.

 

Here is the final code - all working good. Required steps are as follows:

 

1. Run command. SSC

2. Select objects to scale. Title block and material list

4. Enter desired scale. 25

 

(DEFUN C:ssc ()
(setq ocmd (getvar "CMDECHO"))
(prompt "\nSelect Title Block, Mark and Material List to be re-scaled... ")
(setq sscpt1 '(0 0 0))
(setq sscsset1 (ssget))
(setq ss (ssget "X" (list (cons 0 "insert")(cons 2 "pdctitle"))))
(setq ename (ssname ss 0))
(setq data (entget ename))
(setq ssccs (cdr (assoc 41 data)))
(SETQ sscds (getreal "\nEnter Desired Scale : "))
(COMMAND "scale" sscsset1 "" sscpt1 (/ sscds ssccs))
(COMMAND "dimscale" sscds)
(COMMAND "ltscale" (* sscds 10))
(COMMAND "-style" "PDC_Prosteel" "isocp.shx" (* sscds 3.5) "1" "0" "NO" "NO")
(setq ssctso (strcat "1:"(rtos ssccs)))
(setq ssctsn (strcat "1:"(rtos sscds)))
(COMMAND "-attedit" "n" "n" "pdctitle" "pdcscale" "" ssctso ssctsn)
(COMMAND "graphscr")
(setvar "CMDECHO" ocmd)
(princ)
)

 

 

Thanks so much for your help - saves a lot of setup time for the draftees.

 

Cheers.

Link to comment
Share on other sites

  • 4 weeks later...

hi again guys,

 

im afraid ive run into a few issues with this routine and will have to tweak it further. just wondering if anyone can please help me sort these issues out.

 

The problem i am having is that the scaling routine will only work when the DRGs units are set to zero decimal places. The process where the routine needs to find and replace a text string in a block relies on an exact match and the output must be to zero (or one decimal place in the case of half scales).

 

the routine will run perfectly when the DRGs units are set to zero decimal places AND the scale is a whole/round number.

 

- IF the DRGs units are set to anything but zero decimal places... the routine will only partially work, the rescaling will be completed but the title block will not be updated because of the mis-match between the value in the title block having zero decimal places and the entered value been read as having the same ammount of decimal places as the DRG.

 

- IF the DRG units are set to ZERO decimal places and a half scale is used (eg: 7.5)... the routine will only partially work, the rescaling will be completed but the title block will be updated incorrectly. The value in the scale field in the title block will be rounded to the neared round number.

 

 

Can anyone please help me sort this out?

 

Thanks for any help.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...