change attribute to filename

change attribute to filename

Anonymous
Not applicable
2,008 Views
21 Replies
Message 1 of 22

change attribute to filename

Anonymous
Not applicable

Hello all,  i posted this yesterday but it didnt seem to take so i will post again.  i am looking for a lisp that will change and attribute to the file name without the dwg extension.  can anyone help me.

 

thanx

0 Likes
Accepted solutions (1)
2,009 Views
21 Replies
Replies (21)
Message 2 of 22

Anonymous
Not applicable

@Anonymous  Something like ?

A.gif

0 Likes
Message 3 of 22

Moshe-A
Mentor
Mentor

@Anonymous  hi,

 

adding a field to attribute value would be more easy for you.

 

enjoy

moshe

 

 

fn.png

0 Likes
Message 4 of 22

Anonymous
Not applicable

I was actually looking for a lisp routine that would do this.  but thanks for you suggestion.

0 Likes
Message 5 of 22

Anonymous
Not applicable

@Anonymous  Any specific reason?

0 Likes
Message 6 of 22

Anonymous
Not applicable

so I can use it on any drawing without have to go through the field process every time.  we get lots of drawings from clients that don't want us to mess around with any of there blocks. and it is so convenient if it is preloaded.  preferably I would like this without the file extension (dwg) if that is possible.

 

thanks for your help

0 Likes
Message 7 of 22

Anonymous
Not applicable

That doesn't seem necessary to me.

0 Likes
Message 8 of 22

Anonymous
Not applicable

Maybe its more a "want" than a "need" but it is what I prefer.  do you know if this is possible?

 

thanx

0 Likes
Message 9 of 22

ronjonp
Mentor
Mentor
Accepted solution

Your request is kinda vague. What attribute .. is it a specific block? I agree that a field is the way to solve this:

(defun c:foo (/ e el)
  (if (and (setq e (car (nentsel))) (= "ATTRIB" (cdr (assoc 0 (setq el (entget e))))))
    ;; Field
    (entmod (subst '(1 . "%<\\AcVar Filename \\f \"%fn2\">%") (assoc 1 el) el))
    ;; Hardcoded ( not recommended ) .. what if file gets renamed???
;;;    (entmod
;;;      (subst (cons 1 (substr (getvar 'dwgname) 1 (- (strlen (getvar 'dwgname)) 4))) (assoc 1 el) el)
;;;    )
  )
  (princ)
)

 

0 Likes
Message 10 of 22

Anonymous
Not applicable

I tried this and it just changes the attribute to ####.  I want to be able to use this for any attribute nothing specific.  I don't want it to be turned into a field.   Just change the value of the attribute to the file name without the dwg.

 

thanks for your help with this.

0 Likes
Message 11 of 22

Anonymous
Not applicable

I just look at this lisp again and realize you gave me two option.  the hardcode one worked like a charm.

 

thank you very much for this.

0 Likes
Message 12 of 22

ronjonp
Mentor
Mentor

@Anonymous wrote:

I just look at this lisp again and realize you gave me two option.  the hardcode one worked like a charm.

 

thank you very much for this.


Thank you for the thanks but...

 

I don't understand why an OP can accept their post as a solution @Anonymous  ? Give credit where credit is due .. we're all scrappin for unsalted stale peanuts in a nonsensical world that gives us a number that...  ha!

 

 

0 Likes
Message 13 of 22

ronjonp
Mentor
Mentor

@Anonymous wrote:

I tried this and it just changes the attribute to ####.  I want to be able to use this for any attribute nothing specific.  I don't want it to be turned into a field.   Just change the value of the attribute to the file name without the dwg.

 

thanks for your help with this.


All you have to do is regen, It's based on your setting for FIELDEVAL variable. Don't hard code this!

0 Likes
Message 14 of 22

Anonymous
Not applicable

 

 


@ronjonp wrote:

@Anonymous wrote:

I just look at this lisp again and realize you gave me two option.  the hardcode one worked like a charm.

 

thank you very much for this.


Thank you for the thanks but...

 

I don't understand why an OP can accept their post as a solution @Anonymous  ? Give credit where credit is due .. we're all scrappin for unsalted stale peanuts in a nonsensical world that gives us a number that...  ha!

 

 


@ronjonp  I did for you !!

0 Likes
Message 15 of 22

ronjonp
Mentor
Mentor

@Anonymous wrote:

 

 


@ronjonp wrote:

@Anonymous wrote:

I just look at this lisp again and realize you gave me two option.  the hardcode one worked like a charm.

 

thank you very much for this.


Thank you for the thanks but...

 

I don't understand why an OP can accept their post as a solution @Anonymous  ? Give credit where credit is due .. we're all scrappin for unsalted stale peanuts in a nonsensical world that gives us a number that...  ha!

 

 


@ronjonp  I did for you !!


Hahaha .. thanks. 🙂 I still find it odd that you can mark your own posts as solutions.

0 Likes
Message 16 of 22

Anonymous
Not applicable

that was not my intention to accept my own post.  I meant to give credit to where due.  how can I change that?

0 Likes
Message 17 of 22

Anonymous
Not applicable

thank you rperez  but I don't know how to change this.  can you please tell me and I will gladly accept yours as the solution.  I apologize for the mistake.

0 Likes
Message 18 of 22

ronjonp
Mentor
Mentor

@Anonymous wrote:

thank you rperez  but I don't know how to change this.  can you please tell me and I will gladly accept yours as the solution.  I apologize for the mistake.


No need to apologize .. I've seen it done a few times before ( probably on accident ). *cheers*

0 Likes
Message 19 of 22

Anonymous
Not applicable

The best suggestion that I can provide for this type of issues is LongPathTool. Best of luck.

0 Likes
Message 20 of 22

Sea-Haven
Mentor
Mentor

The quick version 

 

(setq ent (entget (car (nentsel "\npick att to change not block"))))
(setq dwg (getvar 'dwgname))
(entmod (subst (cons 1 dwg) (assoc 1 ent) ent))
(vl-filename-base (getvar "dwgname"))

Otherwise you can use this:

(substr (setq str (getvar "dwgname")) 1 (- (strlen str) 4))

 

0 Likes