It is possible "get certain string from file name and change dimention scale " ?

It is possible "get certain string from file name and change dimention scale " ?

Anonymous
Not applicable
2,977 Views
23 Replies
Message 1 of 24

It is possible "get certain string from file name and change dimention scale " ?

Anonymous
Not applicable

hello everyone!

 

It is possible "get certain string from file name and change dimention scale " ?

 

To be specific.. if filename contains 1:100(1:200 or1:300...), it is the same as changing the scale of the dimensions 

 

i found like someting below...

 

 

 

 

 

- read filename

 

(defun C:pTxt()

     (setq fname(getstring "\n Enter a valid file name: "))

      (if(setq f(open fname "r"))

       (while (setq txtLine(read-line f))

        (princ txtLine)

       )        

       (princ "\n Error - Could not find file")

   )             

)       

 

 

 

 

- find certain string from list

 

(defun c:test(/ a yes)
(setq a (list "1" "2" "3"))
(setq yes (searchstring a "2"))
(if(= yes t)
(prompt "found")
(prompt "Not found")
)
)

 

 

 

 

 

- Change Dimension sclae

 

(defun c:Dimsc ( / *error* _StartUndo _EndUndo doc ss deflt old_b_scale alrim bp ojt )
(vl-load-com)
(defun *error* ( msg )
(and doc (_EndUndo doc))
(or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
(princ (strcat "\n** Error: " msg " **")))
(princ)
)

(defun _StartUndo ( doc ) (_EndUndo doc)
(vla-StartUndoMark doc)
)

(defun _EndUndo ( doc )
(if (= 8 (logand 8 (getvar 'UNDOCTL)))
(vla-EndUndoMark doc)
)
)


(setq fname(getstring "\n Enter a valid file name: "))

 

(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))

(if (ssget "_X" '((0 . "*DIMENSION")))
(progn
(setq *scl* 1)
(setq *oscl*
(cond
(
(getdist
(strcat "\nSpecify Overall Scale Factor(Specify Overall Scale Factor) <"
(rtos
(setq *oscl* (cond ( *oscl* ) ( 1.0 )))
)
"> : "
)
)
)
( *oscl* )
)
)

(_StartUndo doc)

(vlax-for o (setq ss (vla-get-ActiveSelectionSet doc))
(mapcar
(function
(lambda ( prop value )
(if (vlax-property-available-p o prop)
(vlax-put-property o prop value)
)
)
)
'(LinearScaleFactor ScaleFactor) (list *scl* *oscl*)
)
)

(vla-delete ss)

(_EndUndo doc)
)
)
(princ)
)

 

 

 

 

 

Therefore, how can i mix these things to create what i want?

Please help me

 

thank you

0 Likes
Accepted solutions (1)
2,978 Views
23 Replies
Replies (23)
Message 2 of 24

john.uhden
Mentor
Mentor

Yes, you can.  The way I am perceiving,  it is based on the current active drawing.

So we can sort of dissect the drawing name looking for a wildcard match as in "*#:###*,**#:####*"

Whatever we create can be run automatically on every drawing open.

 

Is that close to the idea?  No need to wait for me.  The regular predators here will have it all written before I get to work tomorrow.

No, I am not staying up late, well except to maybe watch a little bit of Yankees Encore (I think they played this afternoon).  I greatly miss Jeter and Rivera, but the Baby Bombers and now even Todd Frazier have collectively restored my interest.  Did you know that Todd Frazier starred on the Toms River, NJ team that won the Little League World Series in 1998?  Toms River is only about 15 miles from my home here in Sea Girt.  I worked there when I was just getting started (long before the advent of AutoCAD).  I think the team was nicknamed "The Beast from the East."

John F. Uhden

0 Likes
Message 3 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

hello everyone!

 ..To be specific.. if filename contains 1:100(1:200 or1:300...), it is the same as changing the scale of the dimensions 

 

 


Am I missing something here? is that even possible?

 

possible.PNG

0 Likes
Message 4 of 24

scot-65
Advisor
Advisor
🙂 my thoughts exactly.

Scot-65
A gift of extraordinary Common Sense does not require an Acronym Suffix to be added to my given name.

0 Likes
Message 5 of 24

john.uhden
Mentor
Mentor

Oh, yeah.  That observation was pretty obvious (except to pea-brains like myself; that's what Tony T. called me once).  😕

John F. Uhden

0 Likes
Message 6 of 24

Anonymous
Not applicable

Oops. I think it should be like "1-300".

0 Likes
Message 7 of 24

Anonymous
Not applicable

I found an additional post that might help....

 

(https://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/copy-extract-string-from-filename/td...)

 

(defun c:demo  (/
                drawingName
                discipline
                prefixCode
                theAttributeBlock
                nameToSetPLANNO)

;;;			pBe July 201			lll
;;;							;;;
      (if
            (and
                  (= (getvar 'Dwgtitled) 1)
                  (setq drawingName (getvar 'Dwgname))
                  (setq p (vl-string-position 35 drawingName))
                  (> (setq numberAfterSymbol
                                (atoi (substr drawingName
                                              (+ 2 p))))
                     0)
                  (setq discipline
                             (vl-some
                                   '(lambda (d)
                                          (if (vl-string-search
                                                    d
                                                    drawingName)
                                                (substr d 2)))
                                   '("_AR-" "_ST-" "_IR-" "_PL-")))
                  (setq prefixCode
                             (cond
                                   ((<= 1 numberAfterSymbol 5) "8001-")
                                   ((<= 6 numberAfterSymbol 14) "9001-")
                                   )
                        )
                  (setq theAttributeBlock
                             (ssget "_X"
                                    '((0 . "INSERT")
                                      (410 . "~Model")
                                      (66 . 1)
                                      (2 . "FR_ATTR-T*T"))))
                  )
                 (progn
                       (setq nameToSetPLANNO
                                  (strcat prefixCode
                                          discipline
                                          (nth (strlen (setq sn   (itoa numberAfterSymbol)))
                                               '(nil "0" ""))
                                          sn))

                       (repeat (setq i (sslength theAttributeBlock))
                             (vl-some
                                   '(lambda (atb)
                                          (if   (equal
                                                      (vla-get-tagstring
                                                            atb)
                                                      "PLANNO")
                                                     (vla-put-textstring
                                                           atb
                                                           nameToSetPLANNO)))
                                   (vlax-invoke
                                         (vlax-ename->vla-object
                                               (ssname
                                                     theAttributeBlock
                                                     (setq i (1- i))))
                                         'GetATtributes)
                                   )
                             )
                       )
                 )
      (princ)
      )

 

However, it can not be tested because it does not work.

 

 

0 Likes
Message 8 of 24

pbejse
Mentor
Mentor

@john.uhden wrote:

Oh, yeah.  That observation was pretty obvious (except to pea-brains like myself; that's what Tony T. called me once).  😕


Not too obvious if you think about it., back then you can't include space in a filename and no longer than 8 characters. You never know John.

0 Likes
Message 9 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

I found an additional post that might help....

 

 

 ....However, it can not be tested because it does not work.

 


Wow Smiley Surprised

 

Thank you kamilee2011, very nice of you to say, I'll make a note of that and I will personally file a petition to take it down for you.

 

Smiley Happy Happy days.

 

Message 10 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

Oops. I think it should be like "1-300".


Post an example of a filename, is it like this? 

 

  • Something 1-300 First Floor.dwg
  • 9999-ABC-1-200.dwg

Mind if I ask why do you include a scale in the drawing filename? besides knowing on-the-fly what the scale is just by looking at the file name.

What about a layout sheet with various drawing scale?

Message 11 of 24

Anonymous
Not applicable

Well .. I can not say for all the reasons why this feature is required (because it is needed when uploading a drawing to a specific web system in Korea), but I'll show you some photos that include my intentions.

 

(I will post an integrated post for this work which will include objectives and solutions in the future.)

 

2.JPG

 

 

 

 

0 Likes
Message 12 of 24

roland.r71
Collaborator
Collaborator

Besides the obvious impossibility to use ":" inside filenames...

 

The example code looks hopelessly complex and even irrelevant.

 

"- Read filename" for example will read a given file and display its content line by line (?)

 

where as, if you want to know the current drawings name (and it sure looks like you do / need to) all you need is:

(setq dwgname (getvar "dwgname"))

 

The part to check for the scale can be as simple as:

(setq dwgname (getvar "dwgname")
      scales  '("1-2" "1-10" "1-50" "1-100" "1-200")
      i       0)

(repeat (length scales)
   (setq scale (nth i scales))
   (if (vl-string-search scale dwgname)
      (setq dwgScale (vl-string-subst ":" "-" scale))
   )
   (setq i (1+ i))
)
(princ dwgScale)
(princ)

Use the var "dwgScale" to set your dimension scale and you are done.

 

... but there's a lot more to this, which isn't right and can easily give unwanted results.

 

Filenames containing numbers and dashes for example... a file called "en40621-200_1-10" (where the 1-10 is the scale) would report as 1:200 with the above code...

 

You might want to do a few checks or something to be sure. (if its always at the end, extract the last 5 or 6 chars from the filename and check that for a scale, for example, to prevent the rest of the filename to scramble things up.)

 

Personaly i find it questionable to use the filename to set dimension scales. The other way round, yes, but this is asking for trouble. IMHO

Anyway, this code will help you to do so.

Message 13 of 24

pbejse
Mentor
Mentor

@roland.r71 wrote:

Besides the obvious impossibility to use ":" inside filenames...

 

The example code looks hopelessly complex and even irrelevant.

 



@Anonymous wrote:

I found an additional post that might help.... 

 

 ....However, it can not be tested because it does not work. 


Geez, You guys sure have a way with words! , The praises just keep coming. Smiley Very Happy

 

Message 14 of 24

roland.r71
Collaborator
Collaborator

@pbejse wrote:

@roland.r71 wrote:

Besides the obvious impossibility to use ":" inside filenames...

 

The example code looks hopelessly complex and even irrelevant.

 



@Anonymous wrote:

I found an additional post that might help.... 

 

 ....However, it can not be tested because it does not work. 


Geez, You guys sure have a way with words! , The praises just keep coming. Smiley Very Happy

 


I'm sure the function to display a text files content has some great use, but realy, what's the relevance of such a function for setting a dimension scale based on the filename???

 

Something tells me it's only there, 'cause it says: Read filename

(but "something" can always be wrong, of course)

0 Likes
Message 15 of 24

pbejse
Mentor
Mentor

@roland.r71 wrote:

.... (but "something" can always be wrong, of course)


 

As much as "they" are wrong some of the time. Smiley LOL

 

I understand what you're saying roland.r71, It's just me playing around is all. 

 

Going back to the OP, the task is fairly easy, All I wanted to know is why the scale is included on the filename and some.,

 

I guess the drawings are already done, If so why then did the filename ended up with a different scale name compared to the actual drawing scale?

 

Again, the request is easy as long as we know all the details.

 

pBe

 

 

 

0 Likes
Message 16 of 24

Anonymous
Not applicable

hi. pbejse

 

alright. I will attach a pdf for explanation. Please confirm.

 

thanks.

0 Likes
Message 17 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

hi. pbejse

 

alright. I will attach a pdf for explanation. Please confirm.

 

thanks.


Thank you for letting us know how you the filename were generated. We are on it. 

 

0 Likes
Message 18 of 24

pbejse
Mentor
Mentor

Assumptions:

 

Filename format is "**- 1-####.dwg" ends with dash | space | 1 | dash | scale 

NO TextOverride

Dimension objects are the target and not the dimestyle

 

Also, using the snippet code at post#1 [ Original author: unknown ]

 

(defun c:Dimsc ( / *error* _StartUndo _EndUndo doc ss fname *scl* )
(vl-load-com)
	(defun *error*  (msg)
	      (and doc (_EndUndo doc))
	      (or (wcmatch (strcase msg) "*BREAK,*CANCEL*,*EXIT*")
	          (princ (strcat "\n** Error: " msg " **")))
	      (princ)
	      )
	(defun _StartUndo  (doc)
	      (_EndUndo doc)
	      (vla-StartUndoMark doc)
	      )
	(defun _EndUndo  (doc)
	      (if (= 8 (logand 8 (getvar 'UNDOCTL)))
	            (vla-EndUndoMark doc)
	            )
	      )
      
(setq doc (vla-get-ActiveDocument (vlax-get-acad-object)))
      
(if (and
  	( = (getvar 'dwgtitled) 1)
  	( wcmatch (setq fname (vl-filename-base (getvar 'dwgname))) "*- 1-*#")
	(setq p (vl-string-position 45 fname nil t))
        (setq *scl* (substr fname (+ 2 p)))
        (numberp (setq *scl*  (read *scl*)))
        (ssget "_X" '((0 . "*DIMENSION")))
        )
	(progn
              (_StartUndo doc)
		(vlax-for
	               o  (setq ss (vla-get-ActiveSelectionSet doc))
	              (mapcar
	                    (function
	                          (lambda (prop value)
	                                (if (vlax-property-available-p
	                                          o
	                                          prop)
	                                      (vlax-put-property
	                                            o
	                                            prop
	                                            value)
	                                      )
	                                )
	                          )
	                    '(LinearScaleFactor ScaleFactor)
	                    (list *scl* *scl*)
	                    )
	              )
		(vla-delete ss)
            (_EndUndo doc)
              )
          )
(princ)
)

 

HTH

 

Message 19 of 24

Anonymous
Not applicable

Wow! This is really nice.

 

By the way, I have to change the title of this file to "ex) Floor plan (scale 200) _1st". Can I read only numbers from "(scale ***)" here?

 

Thank you very much.

0 Likes
Message 20 of 24

pbejse
Mentor
Mentor

@Anonymous wrote:

Wow! This is really nice.

 

By the way, I have to change the title of this file to "ex) Floor plan (scale 200) _1st". Can I read only numbers from "(scale ***)" here?

 

Thank you very much.


Yes, just to be clear, is the word scale part of the filename? and the filename format is 1-### (numbers) ?  or just the 100 or 200?

 

0 Likes