Author Topic: Problem with converting SAT-Information  (Read 2642 times)

0 Members and 1 Guest are viewing this topic.

S.Langhammer

  • Guest
Problem with converting SAT-Information
« on: March 12, 2013, 07:04:43 AM »
Hello there everyone!
I'm currently (still) working on the Lisp side of an interface to read information from .dwg files to a custom file. You could say the custom file i produce is a kind of reduced/formated dxf file. I know what a lot of you might think now, but no, simply making a .dxf file out of the dwg is not an option.
The actual Lisp is running on BricsCAD.
SO! the current issue:
I'm using a copy and paste method to convert SAT-entities to inserts, which worked pretty fine so far, but now I'm getting these lines:

CAD 2 File aufgerufen
: ._COPYBASE
Basispunkt wählen:
Objekte wählen, die in die Zwischenablage kopiert werden sollen:
1 gefunden.
Objekte im Satz: 1
Objekte wählen, die in die Zwischenablage kopiert werden sollen:
: ._PASTECLIP
:
Gegenüberliegende Ecke: ._COPYBASE
Eingabe wurde nicht erkannt.  Bitte versuchen Sie es nocheinmal.
Gegenüberliegende Ecke:
:
:
: ÖFFNEN
Name der Zeichnung: ._PASTECLIP
Die angefragte Datei wurde nicht gefunden.: "._PASTECLIP.dwg"
:
Gegenüberliegende Ecke: ._COPYBASE
Eingabe wurde nicht erkannt.  Bitte versuchen Sie es nocheinmal.
Gegenüberliegende Ecke:
:
:
: ÖFFNEN
Name der Zeichnung: ._PASTECLIP
Die angefragte Datei wurde nicht gefunden.: "._PASTECLIP.dwg"
:
Gegenüberliegende Ecke: ._COPYBASE
Eingabe wurde nicht erkannt.  Bitte versuchen Sie es nocheinmal.
Gegenüberliegende Ecke:
:
:
: ÖFFNEN
Name der Zeichnung: ._PASTECLIP
Die angefragte Datei wurde nicht gefunden.: "._PASTECLIP.dwg"
:
Gegenüberliegende Ecke: !!!DXF-Daten exportiert!!!

I'll translate the most important for those of you, who don't understand the German gibberish:

: ÖFFNEN
Name der Zeichnung: ._PASTECLIP
Die angefragte Datei wurde nicht gefunden.: "._PASTECLIP.dwg"
:
Gegenüberliegende Ecke: ._COPYBASE
Eingabe wurde nicht erkannt.  Bitte versuchen Sie es nocheinmal.
Gegenüberliegende Ecke:

==

: Open
Name of the drawing: ._PASTECLIP
The called file was not found.: "._PASTECLIP.dwg"
:
Opposing Corner: ._COPYBASE
Entry not identified. Please try again.
Opposing Corner:

I do understand that there is no ""._PASTECLIP.dwg" file anywhere and that ._COPYBASE can't be an opposing corner. What confuses me is, where in my code do I call for a file? I have to admit, that I found the copy-paste-concept routine on a Forum.
Now here's the code, which propably produces my Problem:

Code - Auto/Visual Lisp: [Select]
  1. (defun convertData (convList / step convList enlist en entTyp)
  2.         (if (/= convList nil)
  3.                 (foreach step convList
  4.                         (setq entTyp (cdr(assoc 0 step)))
  5.                         (if (= entTyp "3DSOLID")
  6.                                 (convSATData)
  7.                                 (if (= entTyp "REGION")
  8.                                         (convSATData)
  9.                                         (if (= entTyp "SURFACE")
  10.                                                 (convSATData)
  11.                                                 (if (= entTyp "BODY")
  12.                                                         (convSATData)
  13.                                                         (if (= entTyp "INSERT")
  14.                                                                 (convBlkData)
  15.                                                         )
  16.                                                 )
  17.                                         )
  18.                                 )
  19.                         )
  20.                 )
  21.         )
  22.         (princ)
  23. );;; -
  24. (defun convBlkData(/ enlist sublist
  25.         (setq enlist step)      (setq subList(list))
  26.         (setq subList(append(Block_EnameListNested (cdr (assoc 2 enlist))) enlist ) )
  27.         (convertData subList)                                                                  
  28.         (princ)
  29. )
  30. ;;; -
  31. (defun convSATData()                                                                           
  32.         (setq en (cdr(assoc -1 step)))
  33.         (setvar "VlipBoardFormat" 19)
  34.         (command "._COPYBASE" '(0.0 0.0 0.0)  en "")
  35.         (command "._PASTECLIP" '(0.0 0.0 0.0))
  36.         (princ)
  37. )
  38.  

Given, that convertData first is called with a list of entities. Now I suspect the way I call convSATData to be the source of all evil here. I'll also attach the original file, where I got the copy paste Thing from.

Thanks for the help everyone!

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Problem with converting SAT-Information
« Reply #1 on: March 12, 2013, 07:34:09 AM »
I'm not sure as to the cause of your error, but your posted code could be written as:

Code - Auto/Visual Lisp: [Select]
  1. (defun convertData ( lst / etp )
  2.     (foreach enx lst
  3.         (cond
  4.             (   (wcmatch (setq etp (cdr (assoc 0 enx))) "3DSOLID,REGION,SURFACE,BODY")
  5.                 (convSATData enx)
  6.             )
  7.             (   (= "INSERT" etp)
  8.                 (convBlkData enx)
  9.             )
  10.         )
  11.     )
  12.     (princ)
  13. )
  14.  
  15. (defun convBlkData ( elst )
  16.     (convertData (append (Block_EnameListNested (cdr (assoc 2 elst))) elst))
  17. )
  18.  
  19. (defun convSATData ( elst )
  20.     (command "_.copybase" "_non" '(0.0 0.0 0.0) (cdr (assoc -1 elst)) "" "_.pasteclip" "_non" '(0.0 0.0 0.0))
  21.     (princ)
  22. )

As far as I am aware, the System Variable "VlipBoardFormat" (or "ClipBoardFormat") does not exist.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with converting SAT-Information
« Reply #2 on: March 12, 2013, 08:12:49 AM »
@S.Langhammer:
I am not sure what causes your problem. Your command line history suggests that the OPEN command was called. Perhaps by an accidental enter (command "") somewhere.

I have to change two things in your code:
- Add a closing parenthesis on line 24.
- Change "VlipBoardFormat" to "ClipBoardFormat" on line 33.
After these changes I do not get errors (tested with two region entity lists).

As Lee has pointed out, your code has plenty of room for improvement.
Maybe skipping the basics (see BricsCAD Forum) is not such a good idea? :kewl:

FWIW: ClipBoardFormat is a BricsCAD only variable.

Lee Mac

  • Seagull
  • Posts: 12914
  • London, England
Re: Problem with converting SAT-Information
« Reply #3 on: March 12, 2013, 08:18:23 AM »
FWIW: ClipBoardFormat is a BricsCAD only variable.

Thanks for the clarification roy, so perhaps it would be better to use:
Code - Auto/Visual Lisp: [Select]
  1. (if (setq cbf (getvar 'clipboardformat))
  2.     (setvar 'clipboardformat 19)
  3. )

Then to reset:
Code - Auto/Visual Lisp: [Select]
  1. (if cbf
  2.     (setvar 'clipboardformat cbf)
  3. )

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with converting SAT-Information
« Reply #4 on: March 12, 2013, 08:39:10 AM »
@ Lee:
You are just too fast! I was just coming back to this post to warn about resetting the variable...

The reason for setting the clipboardformat to 19 (AutoCAD Release 11/12) and using copy+paste is to turn complex entities into 'older' and simpler entities. Since AutoCAD does not have this variable the code will not work for that program. It would be better to perform any (CAD-platform) checks at an earlier point in the program. But maybe the OP is working on a BricsCAD-only application.

S.Langhammer

  • Guest
Re: Problem with converting SAT-Information
« Reply #5 on: March 12, 2013, 12:24:42 PM »
I should clarifie some points:
-the missing right parenthesis on line 24 got lost, when I deletet some comments just for myself in German, i just didn't notice i deleted too much
-thanks Lee Mac for the simplification, I'm in a kind of "get this running asap" Situation, so I try to get it working SOMEHOW before getting it to work properly
-yes ist for a BricsCAD only application

Yes I do noob around in this a lot, but honestly I just care to get my task done and actually improve my understanding beyond "lerning by doing" when I'm under less pressure... and find some time between the other tasks i got.

I'll try your suggestions when i have the time to (an other Task keeps me occupied at the moment), earliest tomorrow. Giant thanks allready!

S.Langhammer

  • Guest
Re: Problem with converting SAT-Information
« Reply #6 on: March 14, 2013, 06:30:54 AM »
OK with the help of Lee Mac and roy_043 (thanks again) I managed to improve and reduce my code to this:

Code - Auto/Visual Lisp: [Select]
  1. (defun getSATList(inList / entTyp subList entity)
  2.         (foreach SATName inList
  3.                 (setq entity (entget SATName))
  4.                 (setq entTyp (cdr (assoc 0 entity)))
  5.                 (cond
  6.                         ((wcmatch entTyp "3DSOLID,REGION,SURFACE,BODY")
  7.                                 (convSATData SATName)
  8.                         )
  9.                         (
  10.                                 (= "INSERT" entTyp)
  11.                                 (setq subList(list))
  12.                                 (setq subList(append(Block_EnameListNested (cdr(assoc 2 entity)))))
  13.                                 (getSATList subList)
  14.                         )
  15.                 )
  16.         )
  17.         (princ)
  18. )
  19.  
  20. (defun convSATData (SATEnName / SATEnName cbf) ; konvertiert eingefügte SAT-Entitäten
  21.                 (if (setq cbf (getvar 'clipboardformat))
  22.                         (setvar 'clipboardformat 19)
  23.                 )
  24.                 (command "_.copybase" "_non" '(0.0 0.0 0.0) SATEnName "" "_.pasteclip" "_non" '(0.0 0.0 0.0))
  25.                 (if cbf
  26.                         (setvar 'clipboardformat cbf)
  27.                 )
  28.         (princ)
  29. )
  30.  

Given that getSATList first is called with a list of all entity names within the model space. It works perfectly fine, as long as the SAT entities are within the modelspace directly ONLY.
As soon as they "hide" within an INSERT they begin to cause trouble.
Usually I get a perfectly working sequence, repeated over and over, till there are no more SAT entities left (translation within parenthesis):

: _.copybase
Basispunkt wählen:_non (choose base point:_non)
 
Objekte wählen, die in die Zwischenablage kopiert werden sollen: (choose objects, that should be copied to the clipboard: )
1 gefunden. (1 found.)
Objekte im Satz: 1 (objects in the set: 1)
Objekte wählen, die in die Zwischenablage kopiert werden sollen: (choose objects, that should be copied to the clipboard: )
: _.pasteclip
Einfügepunkt wählen: _non (choose Insertion Point: _non)

So far so good, but when the SAT entity is within an INSERT I get this (translation within parenthesis):

: _.copybase
Basispunkt wählen:_non (choose base point:_non)
 
Objekte wählen, die in die Zwischenablage kopiert werden sollen:  (choose objects, that should be copied to the clipboard: )
1 war nicht im aktuellen Bereich. (1 was not in the current area.)
1 gefunden.(1 found.)

Objekte wählen, die in die Zwischenablage kopiert werden sollen:  (choose objects, that should be copied to the clipboard: )
: _.pasteclip
: _non

Der Befehl wurde nicht erkannt "NON". Bitte versuchen Sie es erneut. (The command "NON" was not identified. Please try again.)

I feel like I looked at the code lined  a thousand times, but I just can't seem to find what exactly is causing my problem.
As far as I tracked it down I believe it to be somewhere in convSATData, considering the line "(command [...])".
Maybe I should handle the SAT entities within the INSERTs differently?
I can't just explode every INSERT i stumble over, I believe that to cause a lot of unnecessary information.
The last consequence I can think of would be to run through the INSERTs within the model space and explode the ones containing SAT entities over and over until there are no more INSERTS left, that contain SAT entities. But I think that might also produce a lot of unnecessary information as well, but still better than being unable to read SAT information within INSERTs at all...

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with converting SAT-Information
« Reply #7 on: March 14, 2013, 08:41:38 AM »
You can only use the command function on entities that are in the current space. You have to either follow your 'explode' procedure, or create a temporary entity in modelspace from the entity in the block and apply the copy+paste procedure to that entity. Your code is already creating temporary entities.

S.Langhammer

  • Guest
Re: Problem with converting SAT-Information
« Reply #8 on: March 14, 2013, 09:07:32 AM »
Ah so I can't use commands on entities "hidden" within INSERTs.
This is propably a beginners/noob question again: Can I just load my temporary entity to the clipboard and paste it or would i rather say (for example):

Code - Auto/Visual Lisp: [Select]
  1. (command "_region" [region entity])

At least I have to get my temporary entitiy to the model space somehow.

roy_043

  • Water Moccasin
  • Posts: 1895
  • BricsCAD 18
Re: Problem with converting SAT-Information
« Reply #9 on: March 14, 2013, 10:28:06 AM »
There are a number of ways to copy a nested entity from a block definition to modelspace. Since your whole application is based on the manipulation of entity lists it makes sense to use the entmake or entmakex function. The last function works better for your program since it returns the ename of the new entity.

Code - Auto/Visual Lisp: [Select]
  1. (setq enameOfTempEntity (entmakex entityListOfNestedEntity))

The ename of the temporary entity can then be used in your existing copy+paste routine.

S.Langhammer

  • Guest
Re: Problem with converting SAT-Information
« Reply #10 on: March 14, 2013, 10:51:38 AM »
roy_043, Lee Mac, if we ever meet in person I really owe you one!

I still have to figure how to put the temporary entities in the right place (they are placed relatively to the coordinate system, not the INSERT at the Moment) but I'm positive I'll find a way to solve that!