Author Topic: Need help making slight modification to routine  (Read 2301 times)

0 Members and 1 Guest are viewing this topic.

ELOQUINTET

  • Guest
Need help making slight modification to routine
« on: July 31, 2008, 03:52:23 PM »
Hello all,

I have this routine which allows me to copy objects from a drawing and when I paste it into another it will put the original drawings name below it. The problem now is that I will have to add a suffix to some of my drawings that indicates the sheet size, i.e drawing of something (11x17).dwg. I need to strip the red part off if it appears in the filename. How would I modify this to make this possible



Code: [Select]
;copy selected objects to clipboard based on specified basepoint and when pasted in drawing, a mtext label will be created
;4.5" below the insertion point. text will be created on the "I-FIXT-CASE_IDEN" layer, if it doesn't exist, it is created.
;alan thompson 4.16.08
(defun C:CPD()
(setq base_point (getpoint "\nSpecify base point: "))
(princ "\nSelect objects to copy: ")
(setq copy_objects (ssget))
(if copy_objects
(progn
(setvar "insunits" 0)
(setq ptascii_x (car base_point))
(setq ptascii_x (rtos ptascii_x 2 2))
(setq ptascii_y (cadr base_point))
(setq point_calc (rtos (- ptascii_y 4.5)))
(setq label_base (strcat ptascii_x "," point_calc))
(setq clay (getvar "clayer"))
(if (not (tblsearch "layer" "I-FIXT-CASE_IDEN"))
(command "-layer" "m" "I-FIXT-CASE_IDEN" "C" "11" "" "")
(command "-layer" "t" "I-FIXT-CASE_IDEN" "m" "I-FIXT-CASE_IDEN" "C" "11" "" "")
);if
(command "mtext" label_base "Style" "Romans" "h" "4.5" "j" "mc" "w" "0.85" (strcase (vl-filename-base (getvar "dwgname"))) "")
(setq text_label (entlast))
(command "copybase" base_point copy_objects text_label "")
(command "erase" text_label "")
(setvar "clayer" clay)
);progn
);if
(princ)
);defun

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Re: Need help making slight modification to routine
« Reply #1 on: July 31, 2008, 04:40:37 PM »
Sorry, Dan, but I'm confused.
Quote
The problem now is that I will have to add a suffix to some of my drawings that indicates the sheet size, i.e drawing of something (11x17).dwg. I need to strip the red part off if it appears in the filename.
You say you have to add a suffix, but then you say strip it off. Which is it, add or remove?

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Re: Need help making slight modification to routine
« Reply #2 on: July 31, 2008, 04:41:58 PM »
Oh, now that I post the question I think I see the problem....you are adding that suffix to some of your drawing's names, but you don't want that suffix on the inserted block.

Jeff_M

  • King Gator
  • Posts: 4100
  • C3D user & customizer
Re: Need help making slight modification to routine
« Reply #3 on: July 31, 2008, 04:44:31 PM »
This should do it
Code: [Select]
(setq dwgname (vl-filename-base (getvar "dwgname")))
(setq pre (vl-string-position (ascii "(") dwgname)
      post (vl-string-position (ascii ")") dwgname)
      )
(if (and pre
post)
  (progn
    (setq begstr (substr dwgname 1 pre)
  endstr (setq prefix (substr dwgname (+ 2 post)))
  )
    (setq dwgname (strcat begstr endstr))
    )
  )

;;then use the dwgname variable for your text value

ELOQUINTET

  • Guest
Re: Need help making slight modification to routine
« Reply #4 on: July 31, 2008, 05:17:33 PM »
Jeff what is happening is that I am using this routine for copying objects from the design drawings into a drawing which will serve as a block library. We have all of our items coded and this code has the same name as the filename. When I am ready to create the block I have another routine which takes the text and converts it to an attribute and dumps the text into the value field. Here's where the 11x17 part comes in. We are now adding new drawings to existing libraries but the new drawings are 11x17 while the old are 24x36 and are adding this suffix so it is easy for me to batchplot the drawings. I will try the routine tomorrow, just wanted to give you some insight into what I'm using this for, clear as mud. Since you brought it up, It would be nice to have a routine that would add the "space(11x17)" suffix to the filename as this will be part of a maintenance project I will be starting tomorrow. Thanks for your help.
« Last Edit: July 31, 2008, 05:23:23 PM by Eloquintet »

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Need help making slight modification to routine
« Reply #5 on: July 31, 2008, 05:59:53 PM »
Dan,

Take a look at the strcat function for adding text to a string.

Paste this in your command line: (alert (strcat (getenv "username") " you can do it!"))

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: Need help making slight modification to routine
« Reply #6 on: August 01, 2008, 09:09:33 AM »
Ummm I'm pretty confused here. I tried to paste something together but it's not working. I'm not sure if I have the right idea or if the code requires rewriting. Ron I get the logic of what you showed me but not sure how to apply it for what I need. Here's my paste job, don't laugh too hard.

Code: [Select]
;copy selected objects to clipboard based on specified basepoint and when pasted in drawing, a mtext label will be created
;4.5" below the insertion point. text will be created on the "I-FIXT-CASE_IDEN" layer, if it doesn't exist, it is created.
;alan thompson 4.16.08
(defun C:test()
(setq base_point (getpoint "\nSpecify base point: "))
(princ "\nSelect objects to copy: ")
(setq copy_objects (ssget))
(if copy_objects
(progn
(setvar "insunits" 0)
(setq ptascii_x (car base_point))
(setq ptascii_x (rtos ptascii_x 2 2))
(setq ptascii_y (cadr base_point))
(setq point_calc (rtos (- ptascii_y 4.5)))
(setq label_base (strcat ptascii_x "," point_calc))
(setq clay (getvar "clayer"))
(if (not (tblsearch "layer" "I-FIXT-CASE_IDEN"))
(command "-layer" "m" "I-FIXT-CASE_IDEN" "C" "11" "" "")
(command "-layer" "t" "I-FIXT-CASE_IDEN" "m" "I-FIXT-CASE_IDEN" "C" "11" "" "")
);if
(command "mtext" label_base "Style" "Romans" "h" "4.5" "j" "mc" "w" "0.85"
(setq dwgname (vl-filename-base (getvar "dwgname")))
(setq pre (vl-string-position (ascii "(") dwgname)
      post (vl-string-position (ascii ")") dwgname)
      )
(if (and pre
post)
  (progn
    (setq begstr (substr dwgname 1 pre)
  endstr (setq prefix (substr dwgname (+ 2 post)))
  )
    (setq dwgname (strcat begstr endstr))
    )
  )
(setq text_label (entlast))
(command "copybase" base_point copy_objects text_label "")
(command "erase" text_label "")
(setvar "clayer" clay)
);progn
);if
(princ)
);defun

;;then use the dwgname variable for your text value

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Need help making slight modification to routine
« Reply #7 on: August 01, 2008, 10:59:05 AM »
Dan,

I'm still not sure what you are trying to do but give this a try:

Code: [Select]
;;copy selected objects to clipboard based on specified basepoint and when pasted in drawing, a mtext label will be created
;;4.5" below the insertion point. text will be created on the "I-FIXT-CASE_IDEN" layer, if it doesn't exist, it is created.
;;alan thompson 4.16.08
(defun C:CPD (/ base_point clay copy_objects label_base point_calc ptascii_x ptascii_y text_label)
  (setq base_point (getpoint "\nSpecify base point: "))
  (princ "\nSelect objects to copy: ")
  (setq copy_objects (ssget))
  (if copy_objects
    (progn
      (setvar "insunits" 0)
      (setq ptascii_x (car base_point))
      (setq ptascii_x (rtos ptascii_x 2 2))
      (setq ptascii_y (cadr base_point))
      (setq point_calc (rtos (- ptascii_y 4.5)))
      (setq label_base (strcat ptascii_x "," point_calc))
      (setq clay (getvar "clayer"))
      (if (not (tblsearch "layer" "I-FIXT-CASE_IDEN"))
(command "-layer" "m" "I-FIXT-CASE_IDEN" "C" "11" "" "")
(command "-layer" "t" "I-FIXT-CASE_IDEN" "m" "I-FIXT-CASE_IDEN" "C" "11" "" "")
      ) ;if
      (command "mtext"
       label_base
       "Style"
       "Romans"
       "h"
       "4.5"
       "j"
       "mc"
       "w"
       "0.85"
       (suffixtxt "("
  (strcase (vl-filename-base (getvar "dwgname")))
  " (11x17)"
       )
       ""
      )
      (setq text_label (entlast))
      (command "copybase" base_point copy_objects text_label "")
      (command "erase" text_label "")
      (setvar "clayer" clay)
    ) ;progn
  ) ;if
  (princ)
) ;defun

(defun suffixtxt (str2srch text suffix / i)
  (if (setq i (vl-string-search str2srch text))
    (strcat (substr text 1 i) suffix)
    (strcat text suffix)
  )
)

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: Need help making slight modification to routine
« Reply #8 on: August 01, 2008, 01:26:59 PM »
Ron maybe you got confused because I began requesting one thing then added another so i will break them into 2.

my original routine is used in this way:

i go into the design drawing and run the routine and it asks me for the base point
i select a point then select the objects
it captures the objects and the filename
i open my block library and paste it in and it puts the text string 4-1/2" below the basepoint i selected
the filename is like a barcode which identifies that design
then i use another routine which takes this text and converts it to an attribute assigns a tag and it dumps the text string in as the attribute value
then i create a block from all of this

the original routine worked fine until we recently decided to add a suffix of (11x17) to new drawings being added to old libraries. Now when I capture the filename it captures the suffix too on thos files which is what I want to strip off. I tried your routine and when I pasted the contents into a new drawing it did not strip the "space(11x17)" suffix off.

The second routine I brought up would be used for adding the suffix to the filename.

Does this make more sense now?

ronjonp

  • Needs a day job
  • Posts: 7533
Re: Need help making slight modification to routine
« Reply #9 on: August 01, 2008, 01:39:09 PM »
dan,

Change this line:

          (suffixtxt "("
           (strcase (vl-filename-base (getvar "dwgname")))
           " (11x17)"
          )
To:

          (suffixtxt "("
           (strcase (vl-filename-base (getvar "dwgname")))
           ""
          )

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

ELOQUINTET

  • Guest
Re: Need help making slight modification to routine
« Reply #10 on: August 01, 2008, 02:20:54 PM »
Ah yes that's it Ron. The second tool was an afterthought that I'll have to wait and see how much I'll wait and see if I have a need for. I'm not sure at this point how many new drawings I will have to be adding to old libraries. Anyway thanks for your help with this.