Author Topic: Parcing a filename into a block  (Read 8422 times)

0 Members and 1 Guest are viewing this topic.

ronjonp

  • Needs a day job
  • Posts: 7527
Re: Parcing a filename into a block
« Reply #15 on: October 22, 2014, 03:39:06 PM »
Lee,
I like the Lisp, but I can not adjust the acaddoc.lsp. I do not have rights.  I can use it on my machine. But again, what we're .....
Maybe talk to the person that can give you rights. I agree that lisp is the best way to approach this, and Lee's already given you the solution. Beating dead horses has never been fun.  :P

Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Parcing a filename into a block
« Reply #16 on: October 22, 2014, 03:46:21 PM »
 :oops:
WAVES WHITE FLAG...................
I am very  trainable....   (forgive my spelling)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Parcing a filename into a block
« Reply #17 on: October 22, 2014, 06:11:39 PM »
If I can cover 95% of the possibilities.. than I still have something worth while.

unit .. up to 3 char
disc 1 char
type 2 char

syst 3 char
Number 5-7 char (I know this one's going to be a *****)
sheet 1-4 char

I don't know what the max lenth of DIESEL code is but I'm pretty sure it's pretty long.. I think beyond 255 char.

With these additional restrictions on section string lengths, you can use the following DIESEL expressions:

Unit 1-3 chars
Code: [Select]
$(if,$(eq,-,$(substr,$(getvar,dwgname),2,1)),$(substr,$(getvar,dwgname),1,1),$(if,$(eq,-,$(substr,$(getvar,dwgname),3,1)),$(substr,$(getvar,dwgname),1,2),$(if,$(eq,-,$(substr,$(getvar,dwgname),4,1)),$(substr,$(getvar,dwgname),1,3))))
Disc 1 char
Code: [Select]
$(if,$(eq,-,$(substr,$(getvar,dwgname),2,1)),$(substr,$(getvar,dwgname),3,1),$(if,$(eq,-,$(substr,$(getvar,dwgname),3,1)),$(substr,$(getvar,dwgname),4,1),$(if,$(eq,-,$(substr,$(getvar,dwgname),4,1)),$(substr,$(getvar,dwgname),5,1))))
Type 2 chars
Code: [Select]
$(if,$(eq,-,$(substr,$(getvar,dwgname),2,1)),$(substr,$(getvar,dwgname),5,2),$(if,$(eq,-,$(substr,$(getvar,dwgname),3,1)),$(substr,$(getvar,dwgname),6,2),$(if,$(eq,-,$(substr,$(getvar,dwgname),4,1)),$(substr,$(getvar,dwgname),7,2))))
Syst 3 chars
Code: [Select]
$(if,$(eq,-,$(substr,$(getvar,dwgname),2,1)),$(substr,$(getvar,dwgname),8,3),$(if,$(eq,-,$(substr,$(getvar,dwgname),3,1)),$(substr,$(getvar,dwgname),9,3),$(if,$(eq,-,$(substr,$(getvar,dwgname),4,1)),$(substr,$(getvar,dwgname),10,3))))

I also have the following for Sheet 1-4 chars:
Code: [Select]
$(if,$(eq,-,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),5),1)),$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),4),1),$(if,$(eq,-,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),6),1)),$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),5),2),$(if,$(eq,-,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),7),1)),$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),6),3),$(if,$(eq,-,$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),8),1)),$(substr,$(getvar,dwgname),$(-,$(strlen,$(getvar,dwgname)),7),4)))))
However, it would appear that there is indeed a limit on the length of a DIESEL expression, at which point this task becomes impossible to achieve with DIESEL.

I'm afraid that's as far as I am willing to take this, it's been an interesting ride  :lol:

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Parcing a filename into a block
« Reply #18 on: October 23, 2014, 12:21:36 AM »
Mr. Lee is correct..
The DIESEL code to check 3 Characters is approx 430 char long
DIESEL max char length is 460

Even if you left out the last check and simply posted the last 4 characters.. you would need 505 char in your script
a 6 character parce would take ~830  again assuming you just assume and post on the 6 without the check

I did not know any DIESEL code befor I started, and now I know some...

Thanks To Mr. Lee Mac and Ron Jon.. 

For those looking to attempt this.. with no Knowledge.. this is how I learned... see attachments..
I am very  trainable....   (forgive my spelling)

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Parcing a filename into a block
« Reply #19 on: October 23, 2014, 12:27:34 AM »
I would like to know if the LISP Mr. Lee Mac supplied could be modified to run by command instead of automating it thru the acaddoc.lsp.  I do not think I will be given access.. and since we have multiple clients.. I don't see a way of me talking my CAD Manager into this...

Mr. Lee..

I've asked a lot of you in the last few days... I hope I'm not going too far...

I tried to play with the code myself and it did not work.

I've attached a DWG and my edited verson of Mr. Lee's Code.

I am very  trainable....   (forgive my spelling)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Parcing a filename into a block
« Reply #20 on: October 23, 2014, 04:45:41 AM »
I would like to know if the LISP Mr. Lee Mac supplied could be modified to run by command instead of automating it thru the acaddoc.lsp.

Sorry, but what do you mean by 'run by command'?
With the current code, the user can already type the command 'test' at the command-line to run the program.

I've attached a DWG and my edited verson of Mr. Lee's Code.

I haven't checked the block name & tags against your drawing, but after a cursory glance, there is a stray 'A' in the code modified version of the code:

tag  (mapcar 'strcase tag)A

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Parcing a filename into a block
« Reply #21 on: October 23, 2014, 11:35:21 AM »
Thank you,
Still very new to code. I must have fat fingered that in... 
I am very  trainable....   (forgive my spelling)

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Parcing a filename into a block
« Reply #22 on: October 23, 2014, 11:50:24 AM »
Quote
Sorry, but what do you mean by 'run by command'?

I had assumed this was the type of lisp that would auto run upon opening the dwg.   In the code  I saw "(defun c:test"

I after loading I tried to run the LSP by typing in c:test.. and I got "Unknown command"

I may not get permissions to edit the acaddoc.lsp  .  Since the DIESEL code is clearly not an option.. I want to try to adapt this LSP to be run by a COMAND. Forgive me if I'm using the wrong vocabulary. If I can't exicute this code/LSP by command... What do I need to do to the code to make that happen. 

Also, I assumed that I needed to keep the " " around the tag names and block name in the LSP code.  I hope that is correct.

I'm trying hard to learn here, it's a bit of trial by fire...   I managed to figure my way through the DIESEL text, the more Lisp routines I work with the more I learn.. some of it is way over my head.. and sometimes I have those eureaka moments.    I hope you can appreciate my effort. 

This is not a primary function of mine at work.
I am very  trainable....   (forgive my spelling)

Lee Mac

  • Seagull
  • Posts: 12913
  • London, England
Re: Parcing a filename into a block
« Reply #23 on: October 23, 2014, 12:17:26 PM »
Quote
Sorry, but what do you mean by 'run by command'?

I had assumed this was the type of lisp that would auto run upon opening the dwg.   In the code  I saw "(defun c:test"

I after loading I tried to run the LSP by typing in c:test.. and I got "Unknown command"

Just 'test' as noted above  ;-)
You can change this to whatever command name you wish to use - just change c:test to c:YourCommandHere

Also, I assumed that I needed to keep the " " around the tag names and block name in the LSP code.  I hope that is correct.

Correct.

I'm trying hard to learn here, it's a bit of trial by fire...   I managed to figure my way through the DIESEL text, the more Lisp routines I work with the more I learn.. some of it is way over my head.. and sometimes I have those eureaka moments.    I hope you can appreciate my effort. 

This is not a primary function of mine at work.

No problem! - From your attachments, it appears that you understood my DIESEL code just fine, and I appreciate your efforts trying to understand the code, rather than simply copy/pasting.

Lee

DIW_CADtech

  • Bull Frog
  • Posts: 368
  • Push limits, embrace success, & discard failure.
Re: Parcing a filename into a block
« Reply #24 on: October 23, 2014, 01:02:46 PM »
Thank you guys  ..
Love this forum... 

I think this one is closed...   
I am very  trainable....   (forgive my spelling)