TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Brick_top on September 28, 2012, 09:13:08 AM

Title: Convert string to list?
Post by: Brick_top on September 28, 2012, 09:13:08 AM
Anyone knows how to remove the "" from this:

Code: [Select]
"(((-1 . <Entity name: 7ef08940>) (0 . LWPOLYLINE) (330 . <Entity name:
7ef05cf8>) (5 . 1368) (100 . AcDbEntity) (67 . 0) (410 . Model) (8 . 0) (100 .
AcDbPolyline) (90 . 7) (70 . 0) (43 . 0.0) (38 . 0.0) (39 . 0.0) (10 -49522.9
14762.6) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 8723.02 44922.5) (40 .
0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 39807.6 1190.63) (40 . 0.0) (41 . 0.0)
(42 . 0.0) (91 . 0) (10 95035.6 21096.2) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 .
0) (10 110729.0 49748.1) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 134872.0
18080.2) (40 . 0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (10 141512.0 -22937.3) (40 .
0.0) (41 . 0.0) (42 . 0.0) (91 . 0) (210 0.0 0.0 1.0)))"

?

which is the content of a variable
thanks a lot
Title: Re: Convert string to list?
Post by: Lee Mac on September 28, 2012, 09:48:56 AM
You would use the read function, however, since the DXF data has been converted to a string, the entity name pointers (e.g. <Entity name: 7ef08940>) will no longer be accessible and will cause the read function to error since they will be interpreted as two separate symbols which form an invalid dotted pair structure.

For example, the dotted pairs containing entity names would be equivalent to attempting to convert:

$ (read "((-1 . a b))")
; error: extra cdrs in dotted pair on input


Since the two parts of the entity name pointer would be interpreted as two individual symbols:

(-1 . <Entity name: 7ef08940>)

And a dotted pair may only consist of two atoms, no more, no less.
Title: Re: Convert string to list?
Post by: chlh_jd on September 28, 2012, 10:07:37 AM
For re-entmake , I use this
Code: [Select]
(defun obj->str (ent / relst mid)
  (setq relst (list -1 330 330 5 100 100 102 102 410))
  (setq mid (print ent))
  (foreach num relst
    (progn
      (setq mid (vl-remove (assoc num mid) mid))
    )
  )
  (vl-prin1-to-string mid)
)
(defun obj->str->fn (ent fn / f_test str)
  (setq f_test (open fn "a"))
  (setq str (obj->str ent))
  (prin1 str f_test)
  (close f_test)
)
(defun str->obj (str)
  (entmake (string->entlst str))
)
(defun string->entlst  (str / b l res)
  (setq l (string->strlst str ")"))
  (foreach a  l
    (cond ((wcmatch a "*\"*")
   (setq b (string->strlst
     (vl-string-translate
       "\""
       " "
       (vl-string-trim "(" (vl-string-trim " " a)))
     "."))
   (setq res (cons (cons (eval (read (car b)))
(vl-string-trim " " (cadr b)))
   res)))
  ((setq res (cons (read (strcat a ")")) res)))))
  (reverse res))
(defun string->strlst (str del / lst a s1 cha pos i)
  (setq s1 ""
i  0
a  (ascii del)
  )
  (while (setq pos (vl-string-position a str i))
    (setq s1 (substr str (1+ i) (- pos i)))
    (if (/= s1 "")
      (setq lst (cons s1 lst))
    )
    (setq i (1+ pos))
  )
  (setq s1 (substr str (1+ i)))
  (if (/= s1 "")
    (setq lst (cons s1 lst))
  )
  (reverse lst)
)
Title: Re: Convert string to list?
Post by: dgorsman on September 28, 2012, 10:46:44 AM
Better back up a step.  If this is from a (princ...) to the command line, those wrapping double-quotes DON'T ACTUALLY EXIST.  Moreover, the (entget...) function which generates this type of return doesn't return a string value, it returns a list of dotted pairs.

Context is everything - a little more information would lead to a nicely curved garden path, rather than a cloverleaf-intersection.   :wink:
Title: Re: Convert string to list?
Post by: pBe on September 29, 2012, 10:41:03 PM
it looks as if the OP used vl-princ-to-string, notice how the second element of DXF 0 or 8 or 410 looses its double quotes on the string on the first post? --->(0 . LWPOLYLINE)

with princ ---> (0 . "LWPOLYLINE")
with vl-prin1-to-string -- > (0 . \"LWPOLYLINE\")

Now just for the fun of it. go ahead and convert the string [just as it is now]  to a usable data :)

EDIT: Yes, its a challenge :D
Title: Re: Convert string to list?
Post by: Kerry on September 29, 2012, 11:28:00 PM
Better back up a step.  If this is from a (princ...) to the command line, those wrapping double-quotes DON'T ACTUALLY EXIST.  Moreover, the (entget...) function which generates this type of return doesn't return a string value, it returns a list of dotted pairs.

Context is everything - a little more information would lead to a nicely curved garden path, rather than a cloverleaf-intersection.   :wink:

Yes
and
Yes

:)
Title: Re: Convert string to list?
Post by: pBe on September 30, 2012, 12:21:01 AM
Code - Auto/Visual Lisp: [Select]
  1. (defun  RFS (strData / p q d r edata)          ;<- remake From String
  2.   (while (and
  3.            (setq p (vl-string-position 40 strData 0 T))
  4.            (not (equal strData "("))
  5.            )
  6.     (setq q (if
  7.           (setq f (vl-string-search "\n" (setq q (substr strData p))))
  8.            (strcat (substr q 1 f) (substr q (+ f 2)))
  9.            q
  10.            )
  11.       )
  12.     (if
  13.       (setq r (vl-some
  14.             '(lambda (x)
  15.                (if (setq p (vl-string-search x q))
  16.                  x ))
  17.             '("(0 ." "(8 ." "(100 ." "(410 ." "(-1 ." "(5 ." "(330 .")
  18.             )
  19.         )
  20.        (if (member (setq d (read (substr r 2))) '(0 8 100 410))
  21.          (setq edata
  22.             (cons
  23.               (cons d (vl-string-trim ". )" (substr q (strlen r))))
  24.               eData
  25.               )) q
  26.          )
  27.        (setq eData (cons (read q) eData))
  28.        )
  29.     (setq strData (substr strData 1 (- (strlen strData) (strlen q))))
  30.     )
  31.   eData
  32.   )

(entmakex (rts postedstring))

Usable: --->>> Excludes DXF 0 5 330 <<<---but you guys already know that.
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 03:46:17 AM
Better back up a step.  If this is from a (princ...) to the command line, those wrapping double-quotes DON'T ACTUALLY EXIST.  Moreover, the (entget...) function which generates this type of return doesn't return a string value, it returns a list of dotted pairs.

Context is everything - a little more information would lead to a nicely curved garden path, rather than a cloverleaf-intersection.   :wink:

Hi there.

Sorry for the lack of context. I'm using princ to a txt file and then I'm using the read-line function to put the content to a variable, and what I posted is the result of the read-line to a variable.

What I'm trying to do is to save some objects info in a txt file so I can later "rebuild" them when I want.
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 03:51:55 AM
You would use the read function, however, since the DXF data has been converted to a string, the entity name pointers (e.g. <Entity name: 7ef08940>) will no longer be accessible and will cause the read function to error since they will be interpreted as two separate symbols which form an invalid dotted pair structure.

For example, the dotted pairs containing entity names would be equivalent to attempting to convert:

$ (read "((-1 . a b))")
; error: extra cdrs in dotted pair on input


Since the two parts of the entity name pointer would be interpreted as two individual symbols:

(-1 . <Entity name: 7ef08940>)

And a dotted pair may only consist of two atoms, no more, no less.

Thanks a lot for your explanation, fortunately it makes sense to me  :-)
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 03:55:23 AM
it looks as if the OP used vl-princ-to-string, notice how the second element of DXF 0 or 8 or 410 looses its double quotes on the string on the first post? --->(0 . LWPOLYLINE)

with princ ---> (0 . "LWPOLYLINE")
with vl-prin1-to-string -- > (0 . \"LWPOLYLINE\")

Now just for the fun of it. go ahead and convert the string [just as it is now]  to a usable data :)

EDIT: Yes, its a challenge :D

I have to look into those functions, I have a lot to learn it seems
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 03:56:08 AM
Code - Auto/Visual Lisp: [Select]
  1. (defun  RFS (strData / p q d r edata)          ;<- remake From String
  2.   (while (and
  3.            (setq p (vl-string-position 40 strData 0 T))
  4.            (not (equal strData "("))
  5.            )
  6.     (setq q (if
  7.           (setq f (vl-string-search "\n" (setq q (substr strData p))))
  8.            (strcat (substr q 1 f) (substr q (+ f 2)))
  9.            q
  10.            )
  11.       )
  12.     (if
  13.       (setq r (vl-some
  14.             '(lambda (x)
  15.                (if (setq p (vl-string-search x q))
  16.                  x ))
  17.             '("(0 ." "(8 ." "(100 ." "(410 ." "(-1 ." "(5 ." "(330 .")
  18.             )
  19.         )
  20.        (if (member (setq d (read (substr r 2))) '(0 8 100 410))
  21.          (setq edata
  22.             (cons
  23.               (cons d (vl-string-trim ". )" (substr q (strlen r))))
  24.               eData
  25.               )) q
  26.          )
  27.        (setq eData (cons (read q) eData))
  28.        )
  29.     (setq strData (substr strData 1 (- (strlen strData) (strlen q))))
  30.     )
  31.   eData
  32.   )

(entmakex (rts postedstring))

Usable: --->>> Excludes DXF 0 5 330 <<<---but you guys already know that.

Now you have made it very difficult for me to take your challenge... that function did what I wanted!
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 04:03:47 AM
Now that I'm at it...

does anyone know if it would be too slow to "or possible" to store and remake at least 40000 entities stored in a txt file?
Title: Re: Convert string to list?
Post by: Kerry on October 01, 2012, 04:07:44 AM

Do you have control over how they are saved to a file ??
Title: Re: Convert string to list?
Post by: Kerry on October 01, 2012, 04:19:46 AM

You cant re-use handles
You can't re-use ObjectID's

You need a way of asserting that Table objects exist in the target drawing ; ie layers, styles, linetypes etc, etc.


Hint:
Do you know what the acronym DXF stands for ??
Do you know the commands DXFOUT, DXFIN ??
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 04:37:03 AM

Do you have control over how they are saved to a file ??

Well, I haven't done anything like this but in my ignorance I think I can number the entities.
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 04:45:12 AM

You cant re-use handles
You can't re-use ObjectID's

You need a way of asserting that Table objects exist in the target drawing ; ie layers, styles, linetypes etc, etc.


Hint:
Do you know what the acronym DXF stands for ??
Do you know the commands DXFOUT, DXFIN ??

I have just a basic ideia of what handles and objectIDs are.

The table wouldn't be a problem because I want this to work in the file where the objects are created.

DXFOUT and DXFIN are used to import and export dxf files right?


What I want to to is this:

I already have a routine where I store notes of the development of a project.

Now for each note I would like to have the drawing revert or be rebuilt to the stage of when the note was created.
What I'm doing now is creating slides of how the project was when the note was created.

But I would like to somehow say that some entities belong to note nš1 and some other entities belong to note nš 2.

edit - forgot to answer that DXF stands for drawing interchange format

Title: Re: Convert string to list?
Post by: Kerry on October 01, 2012, 04:54:29 AM

Sounds to me as if you could achieve your target with blocks (simply archive the drawing at each report stage)

no code, no maintenance, ...

just name your 'saveas' using the 'stage' number/name/ID
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 05:01:54 AM

Sounds to me as if you could achieve your target with blocks (simply archive the drawing at each report stage)

no code, no maintenance, ...

just name your 'saveas' using the 'stage' number/name/ID

This might be just a little quirk...

But I was trying to avoid that because some projects have lots of versions and that would use a lot more disk space.

In what I was trying to do only the new entities would be stored seperately, and some older ones would need to be deleted.

I think I might be getting into a project too big for my knowledge.
Title: Re: Convert string to list?
Post by: Kerry on October 01, 2012, 06:16:45 AM

I'm not trying to scare you off  the project :)

as dgorsman noted early in the thread, knowing ALL the details is important.

I don't see why the concern about little disk space should stop the project.
It would be easier to cut and paste some entitys from a previous incarnation of the drawing that to write code to control it.

I don't understand exactly what you mean by 'stages' and notes.
In the past I have documented progress and recorded milestone events simply by archiving the drawing (ie save-As) and using a meaningful name for the document. Sometimes this happened several times a day.
It was a critical QA process when we were dealing with recording a drawing state prior to making design changes.

Title: Re: Convert string to list?
Post by: Kerry on October 01, 2012, 06:26:01 AM

This may give you some ideas what I mean:--


http://www.theswamp.org/index.php?topic=17552.msg212071#msg212071
http://www.theswamp.org/index.php?topic=17552.msg212531#msg212531
Title: Re: Convert string to list?
Post by: pBe on October 01, 2012, 09:03:04 AM
....
(entmakex (rts postedstring))

Usable: --->>> Excludes DXF 0 5 330 <<<---but you guys already know that.

Now you have made it very difficult for me to take your challenge... that function did what I wanted!

Don't worry yourself about the "challenge", just having fun is all.

I'm with Kerry on this, i'd rather save the files as DXF or DWG even, sans version and all.



Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 09:39:19 AM

I'm not trying to scare you off  the project :)

as dgorsman noted early in the thread, knowing ALL the details is important.

I don't see why the concern about little disk space should stop the project.
It would be easier to cut and paste some entitys from a previous incarnation of the drawing that to write code to control it.


I think that is the most realistic easier common sense to do it.

I think I was trying to make it "prettier"

Quote
I don't understand exactly what you mean by 'stages' and notes.
In the past I have documented progress and recorded milestone events simply by archiving the drawing (ie save-As) and using a meaningful name for the document. Sometimes this happened several times a day.
It was a critical QA process when we were dealing with recording a drawing state prior to making design changes.

By stages I think I mean revisions?

I decided to add notes to the projects because there are a lot of changes to the projects and in the past I have had a hard time remembering what I did in a file and with which person.

Here is an image of the little routine I use to store and show the notes I'm talking about.

(http://imageshack.us/a/img72/7527/progz.jpg)

It is in portuguese, but I think it is kind of self-explanatory? "Nota" means "Note"

there is another dialog where I write these notes and store them as xrecords.

the little pulldown menu is used to show slides of the corresponding notes.

I also have a "master file" where I put these notes and I have another routine to search these notes, with every note I store the directory of the file so I can open it from the "master file" I decided to do this because there are a lot of small projects I have a hard time finding and with these notes I can find them much more easily.

Ideally in my ignorance what I would like to do is

On the first version of the drawing.

When writing the first development note I can choose to set the entities as related to Note nš 1.

When writing another note. I want to set the new entities as related to Note nš 2, and if any entity is removed from Note nš 1 set it as deleted.

Ideally I could then automatically revert the drawing to any revision.

But now I'm starting to understand how difficult It might be for me to do It.

I guess I'll try to make it as you guys are saying.



Title: Re: Convert string to list?
Post by: pBe on October 01, 2012, 11:09:55 AM
....Ideally I could then automatically revert the drawing to any revision....

That would be neat eh?  :-)
Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 11:11:03 AM
....Ideally I could then automatically revert the drawing to any revision....

That would be neat huh?  :-)

yeah that would be the idea... probably impossible for a guy like me  :-(
Title: Re: Convert string to list?
Post by: pBe on October 01, 2012, 11:17:48 AM
Here's an idea, every succeeding revision would have its own unique layer identifier

N1_A_Anno_text, N1_A_Anno_Dim...

N2_A_Anno_text, N2_A_Anno_Dim...

Freeze the layer when you need to revert to a particular Rev number.

Title: Re: Convert string to list?
Post by: Brick_top on October 01, 2012, 11:21:39 AM
Someone in another thread had a similar ideia using layerstates.

It might be more realistic that way.

Thanks a lot
Title: Re: Convert string to list?
Post by: CAB on October 01, 2012, 02:59:49 PM
Better back up a step.  If this is from a (princ...) to the command line, those wrapping double-quotes DON'T ACTUALLY EXIST.  Moreover, the (entget...) function which generates this type of return doesn't return a string value, it returns a list of dotted pairs.

Context is everything - a little more information would lead to a nicely curved garden path, rather than a cloverleaf-intersection.   :wink:

Hi there.

Sorry for the lack of context. I'm using princ to a txt file and then I'm using the read-line function to put the content to a variable, and what I posted is the result of the read-line to a variable.

What I'm trying to do is to save some objects info in a txt file so I can later "rebuild" them when I want.
I was wondering, do you need to recreate it or compare it to an existing object or both?
Title: Re: Convert string to list?
Post by: CAB on October 01, 2012, 03:03:56 PM
Reading more of your post I would think you would need to create a revision copy each time you added a note.

Or was your intent to selectively recreate selected objects pertaining to that note only & keep the current DWG?

Title: Re: Convert string to list?
Post by: chlh_jd on October 01, 2012, 04:31:15 PM
Dose Landlord want to protect dwg not to be regain by this way (write protect dwg into txt file , and then rebuild dwg )?
Title: Re: Convert string to list?
Post by: Brick_top on October 02, 2012, 04:46:40 AM
Reading more of your post I would think you would need to create a revision copy each time you added a note.

Or was your intent to selectively recreate selected objects pertaining to that note only & keep the current DWG?

Hi there

Yes my intent is to recreate only objects pertaining to that particular note. I'm not clear on it but there might be other problems with the idea, it could easily work with 2 notes but with more notes it might get complicated, I'll try to outline it below.

This is my ideia of how it could work?

With each Note I would have to save to xrecord which version is currently in use and which are the entities that it contains.

For Example:

Note 2 Is composed by entities number x to x from note 1 and entities number x to x from note 2. I guess I would also have to keep adding to every note which entities are to be deleted.
because I know which version is currently in use I know what entities are already drawn and which are to be deleted.


|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

When creating Notes and defining what entities belong to which version:

Note 1 - Would save a txt file for Note 1 with the numbered entities from Note 1 and save to xrecord that version from note 1 is in use and contains entities from number x to x from note 1.

Note 2 - For Note 2 I would compare every entity in the drawing against the ones that are saved in the txt from Note 1. I would then save to note 2 the new entities that are to be drawn. I will save to xrecord that Note 2 contains entities number x to x from Note 1 and number x to x from Note 2. I would also save the entities that are to be deleted from Note 1.

At this time I realize that acoording to which version currently in use and the one I intend to draw I must also save what entities are to be deleted according to the version currently in use.

Note 3 - Would have to compare the existing entities against Notes 1 and 2 to check which ones are to be drawn and deleted.

As of now I'm not thinking of any other problem that may arise... But I guess I'm sure there could be plenty.

Title: Re: Convert string to list?
Post by: Brick_top on October 02, 2012, 04:47:22 AM
Dose Landlord want to protect dwg not to be regain by this way (write protect dwg into txt file , and then rebuild dwg )?

I'm sorry but I think my english is not allowing me to understand your post?
Title: Re: Convert string to list?
Post by: kruuger on October 02, 2012, 05:21:48 AM
hi Brick_top

that's very crazy idea. problem is, how do you want to recreate deleted object like: blocks (dynamic block), formated mtext, splines...more complex objects. this will work rather with simple shape like lines.

i also create something similar to your notes.
my program allow to create short notes (descriptions). we can add point where note refer. it also save actual layer states.
more can be read here (polish site):
http://forum.cad.pl/cadpl-zapisywanie-notatek-w-rysunku-t78051-360.html (http://forum.cad.pl/cadpl-zapisywanie-notatek-w-rysunku-t78051-360.html)
i'm still developing them but "beta" version works fine. routine is prepared for any language translation.
maybe you find it usefull.

kruuger

EDIT: forgot attachment
Title: Re: Convert string to list?
Post by: Brick_top on October 02, 2012, 05:45:38 AM
wow that's really nice! I already had thought about adding some kind of markers.

Yeah I guess those entities you are talking about are the things that will become problems for me because I don't know about them.

In my ignorance I intended to record each entity with the result I get from creating a selection set and using (entget (ssname x index))

Are you saying that with this I don't get all the info I need to draw every entity I need?
Title: Re: Convert string to list?
Post by: kruuger on October 02, 2012, 06:52:15 AM
wow that's really nice! I already had thought about adding some kind of markers.

Yeah I guess those entities you are talking about are the things that will become problems for me because I don't know about them.

In my ignorance I intended to record each entity with the result I get from creating a selection set and using (entget (ssname x index))

Are you saying that with this I don't get all the info I need to draw every entity I need?
there is no way to entmake dynamic block or create them with vlisp.
some entities will be very very, hard to recreate 100%.
k.
Title: Re: Convert string to list?
Post by: Brick_top on October 02, 2012, 06:54:25 AM
hehe.. I guess there goes my ideia! thank you for your input
Title: Re: Convert string to list?
Post by: kruuger on October 02, 2012, 07:23:38 AM
hehe.. I guess there goes my ideia! thank you for your input
there is something what might work but...dwg will be huge and heavy.
1. create a copy of ALL objects
2. when you create your Note1 point go thru all copies and add Xdata (Note1).
3. rename (with copy) all blocks to name_Note1
4. when add another NoteX follow step 1-3
using visibility properties show/hide notes with xdata
kruuger
Title: Re: Convert string to list?
Post by: CAB on October 02, 2012, 07:48:22 AM
wow that's really nice! I already had thought about adding some kind of markers.

Yeah I guess those entities you are talking about are the things that will become problems for me because I don't know about them.

In my ignorance I intended to record each entity with the result I get from creating a selection set and using (entget (ssname x index))

Are you saying that with this I don't get all the info I need to draw every entity I need?
there is no way to entmake dynamic block or create them with vlisp.
some entities will be very very, hard to recreate 100%.
k.
How about WBLOCK objects and forget about the text file for entities.
Title: Re: Convert string to list?
Post by: kruuger on October 02, 2012, 08:12:27 AM
wow that's really nice! I already had thought about adding some kind of markers.

Yeah I guess those entities you are talking about are the things that will become problems for me because I don't know about them.

In my ignorance I intended to record each entity with the result I get from creating a selection set and using (entget (ssname x index))

Are you saying that with this I don't get all the info I need to draw every entity I need?
there is no way to entmake dynamic block or create them with vlisp.
some entities will be very very, hard to recreate 100%.
k.
How about WBLOCK objects and forget about the text file for entities.
yes. but this is addittional files on hard drive. Brick_top don't want to do this if i understand
k.
Title: Re: Convert string to list?
Post by: Brick_top on October 03, 2012, 03:56:55 AM
hehe.. I guess there goes my ideia! thank you for your input
there is something what might work but...dwg will be huge and heavy.
1. create a copy of ALL objects
2. when you create your Note1 point go thru all copies and add Xdata (Note1).
3. rename (with copy) all blocks to name_Note1
4. when add another NoteX follow step 1-3
using visibility properties show/hide notes with xdata
kruuger

Yeah size could be a problem, I guess I can try it.
Title: Re: Convert string to list?
Post by: Brick_top on October 03, 2012, 04:15:33 AM
hi Brick_top

that's very crazy idea. problem is, how do you want to recreate deleted object like: blocks (dynamic block), formated mtext, splines...more complex objects. this will work rather with simple shape like lines.


Hi,

I tried to recreate an spline from txt file using your RFS function and it worked fine. But I did not succeed creating an mtext though :(
Title: Re: Convert string to list?
Post by: CAB on October 03, 2012, 07:53:56 AM
You may want to strip unwanted dxf codes before storing the data in the text file.
Take a look at this routine which strips unwanted codes.
http://www.theswamp.org/index.php?topic=31145.0
Title: Re: Convert string to list?
Post by: Brick_top on October 04, 2012, 03:38:11 AM
Wow you guys are too good  :-o

Do you mean you can create any object with that routine?

At least there is hope it seems  :-)
Title: Re: Convert string to list?
Post by: kruuger on October 04, 2012, 04:05:55 AM
Wow you guys are too good  :o

Do you mean you can create any object with that routine?

At least there is hope it seems  :)
most of objects but not all.
k.
Title: Re: Convert string to list?
Post by: Brick_top on October 04, 2012, 04:27:38 AM
Wow you guys are too good  :o

Do you mean you can create any object with that routine?

At least there is hope it seems  :)
most of objects but not all.
k.

Can you tell me how do I learn which objects are those?

Title: Re: Convert string to list?
Post by: kruuger on October 04, 2012, 05:06:17 AM
Wow you guys are too good  :o

Do you mean you can create any object with that routine?

At least there is hope it seems  :)
most of objects but not all.
k.

Can you tell me how do I learn which objects are those?
for sure dynamic block. maybe multileader
per CAB routine info: multliline, Make Hatch Non-associative if was, Make Leader Non-associative, table
who knows what else.
what if user change: layer, dimstyle etc ?
kruuger
Title: Re: Convert string to list?
Post by: Kerry on October 04, 2012, 05:38:44 AM
Brick_top ,

What is the actual purpose of saving this data ??

What do you intend doing with these saved entities ??

How often do you want to save them ?

How often will you want to restote them ?

Will any restore be a full restore or partial ?

How many people in your group will be writing data ?

Will you me writing from one model/control  drawing or from several ?

How many drawings in the project ?


This might seem like a lot of questions, but these are things that will govern your best solution design.


Personally I think you will be best served doing a Wblock of selective DXFOut of the relevent entities ... but that belief may change depending on your intent.


Regards
Title: Re: Convert string to list?
Post by: Brick_top on October 04, 2012, 06:47:48 AM
Brick_top ,

What is the actual purpose of saving this data ??

I wanted a way to have a drawing revert to several versions defined by me in another routine I have to save development notes. Withouth having severall full versions of the drawing saved in disk.

What do you intend doing with these saved entities ??

I would like to say that each version of a drawing is related to a note I made and if I want I can have the drawing revert to that state

How often do you want to save them ?

As often as some revision is made to the project

How often will you want to restote them ?

As often as requested by anyone who wants to see another version of a drawing.

Will any restore be a full restore or partial ?

I don't think there will be a full restore, if it happened it would be extremely rare

How many people in your group will be writing data ?

I'll be the only one writing data

Will you me writing from one model/control  drawing or from several ?

I don't know if I understand this question correctly, but every entity would only be reverted to its original creation drawing.

How many drawings in the project ?

This would be only to work in one drawing at a time, to show its several versions. Every drawing would have its own notes and versions saved to its own saved versions

This might seem like a lot of questions, but these are things that will govern your best solution design.


Personally I think you will be best served doing a Wblock of selective DXFOut of the relevent entities ... but that belief may change depending on your intent.

Regards

I don't know if you read a post I made in this thread that I think oultlines my ideia, maybe you read it but I didn't explain myself correctly.

Here is what I said.

Quote
This is my ideia of how it could work?

With each Note I would have to save to xrecord which version is currently in use and which are the entities that it contains.

For Example:

Note 2 Is composed by entities number x to x from note 1 and entities number x to x from note 2. I guess I would also have to keep adding to every note which entities are to be deleted.
because I know which version is currently in use I know what entities are already drawn and which are to be deleted.

|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

When creating Notes and defining what entities belong to which version:

Note 1 - Would save a txt file for Note 1 with the numbered entities from Note 1 and save to xrecord that version from note 1 is in use and contains entities from number x to x from note 1.

Note 2 - For Note 2 I would compare every entity in the drawing against the ones that are saved in the txt from Note 1. I would then save to note 2 the new entities that are to be drawn. I will save to xrecord that Note 2 contains entities number x to x from Note 1 and number x to x from Note 2. I would also save the entities that are to be deleted from Note 1.

At this time I realize that acoording to which version currently in use and the one I intend to draw I must also save what entities are to be deleted according to the version currently in use.

Note 3 - Would have to compare the existing entities against Notes 1 and 2 to check which ones are to be drawn and deleted.

As of now I'm not thinking of any other problem that may arise... But I guess I'm sure there could be plenty.


I'm sorry if I'm giving you guys a lot of work.

I'm thinking this isn't very feasible or worth the trouble.

Title: Re: Convert string to list?
Post by: irneb on October 04, 2012, 03:08:50 PM
It does sound like a big job. Though it might not be entirely impossible. The point about which codes to save or not, is not an easy one to answer, especially not in the case you're referring to:

I.e. you want a record of created, modified and/or erased entities, to allow a persistent partial-undo to be performed to any one of the variants?

If that's the case, then the "simplest" solution would be using a wblock (as someone's suggested previously), actually I'd go this route since IMO it's also the "best" solution. Basically, you'd select the object(s) and wblock selected to a new filename (you can calculate such name from something like the current date/time). Then if you need any further data for such (e.g. who performed the change, or any comments made for such), that can be saved into a TXT file with the same name, or you can add it as DWG propery into the WBlocked DWG file through ObjectDBX. All this can quite easily be automated through lisp (both the WBlocked DWG and the TXT). Not to mention, the wblock would handle the "What codes to save out" for you, actually DXFOut would do the same, but if you're doing it RAW in lisp to a txt file - you'd need to figure these out through trial-n-error. Not to mention: those ENames (which can't be read back) still needs to be saved out somehow - they refer to stuff like linked entities / dictionaries / object data / etc. So if you leave such out, you won't be able to return to a exact state for that entity - it might have "lost" some info in such process (this is why I say it would be trial-n-error).

If you're really pressed on disc space, then saving only the actually needed data into a TXT file "might" help ... though I'm not sure it will actually be smaller than the WBlock in all instances. The txt file saved from lisp would be very similar in size to a DXF file (as done through the SaveAs / DXFOut command) - at least if you save all the relevant data such as Layers/Styles/Blocks/Dictionaries/XData/etc. The reason I'm saying this is the DWG file created using WBlock is a normal Binary DWG file, and the newer ACads (I think since 2005) uses a form of compression (similar to ZIP) to reduce the filesize even further, the DXF/TXT on the other hand is very wasteful on space (e.g. in the binary it might use something like 2 bytes to store an integer code for what type of entity it is; but in DXF the entire Entity Name needs to be saved, one byte per letter - not to mention some form of stating what this portion of the file relates to). So even for the possible space-saving by omitting unneeded data, I'd think twice about going this route: lots of work for possibly even larger files.

If you really want it to be as small as possible, then you might rather want to generate a binary file of your own design. And in such case you might have to look into using DotNet (or at the very least some ActiveX streaming library through Visual Lisp). In which case you can even use some compression libraries to make that binary file even smaller than the DWG could possibly be. This I'd go for only as an extreme last resort - if you've got this type of problem with size, then you need to look elsewhere for easier / better / cheaper solutions like buying a NAS box with 16TB of storage  :lmao:
Title: Re: Convert string to list?
Post by: Brick_top on October 08, 2012, 05:21:16 AM
It does sound like a big job. Though it might not be entirely impossible. The point about which codes to save or not, is not an easy one to answer, especially not in the case you're referring to:

I.e. you want a record of created, modified and/or erased entities, to allow a persistent partial-undo to be performed to any one of the variants?

If that's the case, then the "simplest" solution would be using a wblock (as someone's suggested previously), actually I'd go this route since IMO it's also the "best" solution. Basically, you'd select the object(s) and wblock selected to a new filename (you can calculate such name from something like the current date/time). Then if you need any further data for such (e.g. who performed the change, or any comments made for such), that can be saved into a TXT file with the same name, or you can add it as DWG propery into the WBlocked DWG file through ObjectDBX. All this can quite easily be automated through lisp (both the WBlocked DWG and the TXT). Not to mention, the wblock would handle the "What codes to save out" for you, actually DXFOut would do the same, but if you're doing it RAW in lisp to a txt file - you'd need to figure these out through trial-n-error. Not to mention: those ENames (which can't be read back) still needs to be saved out somehow - they refer to stuff like linked entities / dictionaries / object data / etc. So if you leave such out, you won't be able to return to a exact state for that entity - it might have "lost" some info in such process (this is why I say it would be trial-n-error).

If you're really pressed on disc space, then saving only the actually needed data into a TXT file "might" help ... though I'm not sure it will actually be smaller than the WBlock in all instances. The txt file saved from lisp would be very similar in size to a DXF file (as done through the SaveAs / DXFOut command) - at least if you save all the relevant data such as Layers/Styles/Blocks/Dictionaries/XData/etc. The reason I'm saying this is the DWG file created using WBlock is a normal Binary DWG file, and the newer ACads (I think since 2005) uses a form of compression (similar to ZIP) to reduce the filesize even further, the DXF/TXT on the other hand is very wasteful on space (e.g. in the binary it might use something like 2 bytes to store an integer code for what type of entity it is; but in DXF the entire Entity Name needs to be saved, one byte per letter - not to mention some form of stating what this portion of the file relates to). So even for the possible space-saving by omitting unneeded data, I'd think twice about going this route: lots of work for possibly even larger files.

If you really want it to be as small as possible, then you might rather want to generate a binary file of your own design. And in such case you might have to look into using DotNet (or at the very least some ActiveX streaming library through Visual Lisp). In which case you can even use some compression libraries to make that binary file even smaller than the DWG could possibly be. This I'd go for only as an extreme last resort - if you've got this type of problem with size, then you need to look elsewhere for easier / better / cheaper solutions like buying a NAS box with 16TB of storage  :lmao:

I'm sorry for only replying today, I just returned to work.

I'm feeling guilty for opening this thread now... Is there a limited number of times to ask for help in this place?

The question about notes I think is already solved. The thing about rebuilding the drawings is supposed to be added to a routine I have that handles these development notes.

If I may show here is how it works.

Here are the options to See Notes/add Notes - "Ver Notas/ Adicionar Notas"

(http://imageshack.us/a/img692/1629/infoini.png)

I can then choose to add a Note:

Where it says "Criar Imagens?" Means I can choose to take slides of the state of the drawing and "attach" them to the Note.

Numero de Slides a criar? Its for me to input the number of slides I which to create.

(http://imageshack.us/a/img854/2568/addnotes.png)

When I choose to See the Notes:

The little pull down menu is used to show the slides I saved in the corresponding Note.

(http://imageshack.us/a/img72/7527/progz.jpg)

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||

I also Have a "Master file" in which I also record at its creation time the notes that describe each drawing so I can later search and open a file I want.

Here is where I input what I want to search. In this case I wrote "Pacheco" which is the name of a person I work for.

(http://imageshack.us/a/img51/1219/searchini.png)

If any result is found here is how they appear:

I can than choose to open a file pertaining to a note. In this case Note 37.

(http://imageshack.us/a/img267/5227/searchresult.png)

||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||


What I would like is to replace the slides thing with the "Drawing versions" Idea.

What I'm not understaning about the wblock ideia is how would I compare the wblock entities from a note with new entities?

edit - very informative post, and by the way... what I know about ObjectDBX is I heard the word somewhere :(. by the way I also checked and a txt with the entities gets much larger than a dwg.
Title: Re: Convert string to list?
Post by: kruuger on October 08, 2012, 05:57:57 AM
for compare dwg you need separate tool like:
- furix http://www.furix.com/comparedwg (http://www.furix.com/comparedwg) (there is a trial)
- http://apps.exchange.autodesk.com/ACD/Detail/Index?id=appstore.exchange.autodesk.com%3afastfilediff%3aen (http://apps.exchange.autodesk.com/ACD/Detail/Index?id=appstore.exchange.autodesk.com%3afastfilediff%3aen) (there is also trial), i found few bugs, still no updated version.

could you post a sample dwg to see how big and complicated they are ?

kruuger
Title: Re: Convert string to list?
Post by: Brick_top on October 08, 2012, 06:16:03 AM
I wouldn't like to use an external application to do this?

Here is a typical file of a project, I guess it is badly organized.
Title: Re: Convert string to list?
Post by: kruuger on October 08, 2012, 07:07:23 AM
I wouldn't like to use an external application to do this?

Here is a typical file of a project, I guess it is badly organized.
to wrote good compare program would be another problem.
and yes, dwg is real mess. there should be more blocks!

it doesn't look so big, maybe you should try my Xdata idea ?
kruuger
Title: Re: Convert string to list?
Post by: Brick_top on October 08, 2012, 08:48:37 AM
You mean this one right?

there is something what might work but...dwg will be huge and heavy.
1. create a copy of ALL objects
2. when you create your Note1 point go thru all copies and add Xdata (Note1).
3. rename (with copy) all blocks to name_Note1
4. when add another NoteX follow step 1-3
using visibility properties show/hide notes with xdata
kruuger

When you say visibility properties you mean layer visibility right?

Problem might be that many times the projects suffer very small changes and for any change I would have a complete copy of the drawing. In case I understood your ideia.
Title: Re: Convert string to list?
Post by: kruuger on October 08, 2012, 09:11:41 AM
You mean this one right?

there is something what might work but...dwg will be huge and heavy.
1. create a copy of ALL objects
2. when you create your Note1 point go thru all copies and add Xdata (Note1).
3. rename (with copy) all blocks to name_Note1
4. when add another NoteX follow step 1-3
using visibility properties show/hide notes with xdata
kruuger

When you say visibility properties you mean layer visibility right?
no. i want use object visibility, dxf code 60. try attached program - HID

Problem might be that many times the projects suffer very small changes and for any change I would have a complete copy of the drawing. In case I understood your ideia.
ehh, yes. everywhere problems, problems, problems...
so combination of wblock and visibility:
- each note create "snapshot" of your dwg (separate file - wblock)
- when you back to previous note the whole drawing will be "turned off" (using visibility)
- temporary rename all blocks name
- then program will attach required file as an xref or insert as block
- back to latest version will detach all files (delete blocks), unrename blocks, turn on object

kruuger
Title: Re: Convert string to list?
Post by: Brick_top on October 08, 2012, 09:16:31 AM
Maybe with xdata and wblock?

Assuming I can insert a drawing, explode it and compare it with entities from the same drawing:

I could add this xdata to these supposed objects:

Note 1 - e1
Note 1 - e2
Note 1 - e3
Note 1 - e4

...and wblock these entities.

Then along with the Note 1 description which I add to xrecord I would also add that Note 1 contains entities from e1 to e4, and that version from Note 1 is in use.

In Note 2

I would have to insert the wblock from Note 1 and compare it with the current version to check if any of the entities from Note 1 - e1 to e4 is missing.

If any is missing I would have  to add to xrecord that Note 2 deletes these entities. For Example Note 1 - e4.

Then any entities without xdata would be named:

Note 2 - e1
Note 2 - e2
Note 2 - e3

.. wblock again and store the filename in xrecord.

Then I would add to xrecord that version from Note 2 contains entities from Note 1 from e1 to e3 and entities from Note 2 from e1 to e3.

If all my assumptions are correct (big if) this could work I guess.


Title: Re: Convert string to list?
Post by: Brick_top on October 08, 2012, 09:23:56 AM
You mean this one right?

there is something what might work but...dwg will be huge and heavy.
1. create a copy of ALL objects
2. when you create your Note1 point go thru all copies and add Xdata (Note1).
3. rename (with copy) all blocks to name_Note1
4. when add another NoteX follow step 1-3
using visibility properties show/hide notes with xdata
kruuger

When you say visibility properties you mean layer visibility right?
no. i want use object visibility, dxf code 60. try attached program - HID

Problem might be that many times the projects suffer very small changes and for any change I would have a complete copy of the drawing. In case I understood your ideia.
ehh, yes. everywhere problems, problems, problems...
so combination of wblock and visibility:
- each note create "snapshot" of your dwg (separate file - wblock)
- when you back to previous note the whole drawing will be "turned off" (using visibility)
- temporary rename all blocks name
- then program will attach required file as an xref or insert as block
- back to latest version will detach all files (delete blocks), unrename blocks, turn on object

kruuger

maybe this could work
Title: Re: Convert string to list?
Post by: kruuger on October 09, 2012, 07:07:16 AM
hi Brick_top

here is very rough sketch of what i describe
1. extract Note folder to drive D:
2. open latest.dwg
3. load lsp
4. type REC
5. select required Note
6. one xref overlay above another. it shouldn't be like that but i have a problem with refreshing screen when dcl is open
7. after cancel latest view is restored

kruuger
Title: Re: Convert string to list?
Post by: Brick_top on October 09, 2012, 08:18:33 AM
hi Brick_top

here is very rough sketch of what i describe
1. extract Note folder to drive D:
2. open latest.dwg
3. load lsp
4. type REC
5. select required Note
6. one xref overlay above another. it shouldn't be like that but i have a problem with refreshing screen when dcl is open
7. after cancel latest view is restored

kruuger

wow.. this is too cool man! Now I'm even more willing to do this
Title: Re: Convert string to list?
Post by: Brick_top on October 09, 2012, 08:27:20 AM
Unfortunately this makes me realize how little I know about this... there is so much I don't understand in your routine that it hurts.

I just know a couple of things and my routines all revolve around that.


edit - by the way i don't find it necessary to change between versions while the routine is running. Only one optional rebuild per run is enough.
Title: Re: Convert string to list?
Post by: Brick_top on October 09, 2012, 08:31:13 AM
Love the way you create the dcl without a separate file  :-o  Is there any problem with that approach?
Title: Re: Convert string to list?
Post by: kruuger on October 09, 2012, 08:58:02 AM
Unfortunately this makes me realize how little I know about this... there is so much I don't understand in your routine that it hurts.
there are a lot of library function. probably can be squeeze a little without them.

edit - by the way i don't find it necessary to change between versions while the routine is running. Only one optional rebuild per run is enough.
yes, but i have a problem with refresh xref, when detach-attach. anyone have solution how to refresh view when dcl is open? looks like redraw not working

Love the way you create the dcl without a separate file  :o  Is there any problem with that approach?
no. many user do this here. you can very easy create multi-language file.

kruuger

Title: Re: Convert string to list?
Post by: Brick_top on October 10, 2012, 06:20:21 AM
I'm having a hard time accessing objects within a block.

Is this close to what I need?

Code: [Select]
(setq ent (car (entsel "Pick a block: ")))

           (while
             (/= (cdr (assoc 0 (setq elst (entget (setq ent (entnext ent)))))) "SEQEND")
             (setq entlst (append elst entlst))
           );while

edit - I took out "progn" from this code
Title: Re: Convert string to list?
Post by: kruuger on October 12, 2012, 03:13:45 AM
Code: [Select]
; =========================================================================================== ;
; Lista obiektow w definicji bloku / List of objects in block definition                      ;
;  Name   [STR] - nazwa bloku / block name                                                    ;
;  Entity [STR] - nazwa entycji / entity name                                                 ;
; ------------------------------------------------------------------------------------------- ;
; (cd:BLK_GetEntity "*Model_space" nil), (cd:BLK_GetEntity "NAZWA" "*LINE")                   ;
; =========================================================================================== ;
(defun cd:BLK_GetEntity (Name Entity / en dt res)
  (setq en (tblobjname "BLOCK" Name))
  (while
    (and
      en
      (setq en (entnext en))
      (setq dt (entget en))
      (/= "ENDBLK" (cdr (assoc 0 dt)))
    )
    (if
      (if Entity
        (wcmatch (cdr (assoc 0 dt)) (strcase Entity))
        (cdr (assoc 0 dt))
      )
      (setq res
        (cons
          (cdr (assoc -1 dt))
          res
        )
      )
    )
  )
  (reverse res)
)
kruuger
Title: Re: Convert string to list?
Post by: Brick_top on October 12, 2012, 03:47:16 AM
Thank you  for answering again kruuger.

but i'm really sorry to say that I think I might not be using your routine correctly.

what do you mean by this?

Quote
Entity [STR] - nazwa entycji / entity name


edit - now I understand.. and it works! I was thinking it would return every entity in a block and not only one type that I might choose.

I would prefer for it to create a list of every entity in the block, I'll see if I'm able to modify your code.


Many thinks sir!



Title: Re: Convert string to list?
Post by: Brick_top on October 12, 2012, 03:53:29 AM
Hi there it seems that my "code" above kind of works by changing "SEQEND" for "ENDBLK", but it only returns 2 entities and my block has 3. I'll keep searching.
Title: Re: Convert string to list?
Post by: kruuger on October 12, 2012, 04:09:13 AM
Thank you  for answering again kruuger.

but i'm really sorry to say that I think I might not be using your routine correctly.

what do you mean by this?

Quote
Entity [STR] - nazwa entycji / entity name


edit - now I understand.. and it works! I was thinking it would return every entity in a block and not only one type that I might choose.

I would prefer for it to create a list of every entity in the block, I'll see if I'm able to modify your code.


Many thinks sir!
second argument as nil and you got all objects
kruuger
Title: Re: Convert string to list?
Post by: Brick_top on October 12, 2012, 05:26:51 AM
Thanks again  :-)
Title: Re: Convert string to list?
Post by: CADDOG on October 16, 2012, 11:57:50 AM
hi Brick_top

here is very rough sketch of what i describe
1. extract Note folder to drive D:
2. open latest.dwg
3. load lsp
4. type REC
5. select required Note
6. one xref overlay above another. it shouldn't be like that but i have a problem with refreshing screen when dcl is open7. after cancel latest view is restored

kruuger

I know he said he didn't need it (item 6).....
I wanted to just update the code and resubmit, but I don't know which action_tile is commiting the work.
I moved the new_dialog call to the t cond, and added the following usage of preview
Also need a call to restore dialog settings harvested before closing.
Code: [Select]
( T
     (setq preview 2)
     (while (>= preview 2)
       (new_dialog "StdListDialog" dc ""
      (cond
( *cd-TempDlgPosition* )
( (quote (-1 -1)) )
)
      )
       (if settings (restore_dialog_settings_defun))

Leaving the call to start_dialog in it's current location, it would look like this
Code: [Select]
(setq preview (start_dialog))
Which ever action_tile that performed the changes can substitute it's definition with something like
Code: [Select]
"(setq settings (dialog_save_settings_defun))(done_dialog 4)"
Now immediately after start_dialog (mentioned above), perform another cond
Code: [Select]
    (cond
((= 4 preview)
(previewMyChanges_defun)
)
);cond
);while preview >=2 ;cycles back to our dialog

Any other call to done_dialog will generate preview = 1, which will exit the while statement.
Title: Re: Convert string to list?
Post by: kruuger on October 17, 2012, 06:55:11 AM
thanks CADDOG

it looks like vla-regen do what i want. of course with heavy xrefs will be very slow.
Code: [Select]
...
  (defun _XrefNote (Val / xr)
    (setq xr (kr:BLK_AttachXref "d:\\Note" Val '(0 0 0) 1 1 1 0 nil))
    (vla-regen (vla-get-ActiveDocument (vlax-get-acad-object)) acActiveViewport)
    (if (/= Val fl)
...