JerryFiedler Posted November 8, 2021 Posted November 8, 2021 Greetings, I use Lee Mac's program ms2ps. http://www.lee-mac.com/ms2ps.html The program works very well until it doesn't. I can be using it on various viewports several times getting the correct results. Then, for reasons I do not know, it will stop working properly. Specifically, I create a new viewport and the objects are copied to the wrong location. Sometimes the objects are incorrectly rotated, sometimes they are just translated far from the viewport frame. I would guess the transformation calculations are failing. If I go back to a viewport where the program previously worked I find it still works. Great! If I return to a "broken" viewport it is still not working. I only point that out since it seems to me the problem could be in the properties of the viewports (some work; some don't). My review of the viewport properties did not turn up anything that looks odd. All the DXF property keys that the program uses seem to be reasonable. The viewports are just simple rectangles. For the majority of the time the program works flawlessly. When I come upon a "broken" viewport I save the dwg file, close the file and then reopen file. Now ALL the viewports seem to work correctly. (Until, at some point, the problem returns). That obviously is a clumsy "fix". Since reopening the file clears or resets many variables perhaps the program is changing some variable but not resetting them before it terminates. Now, finally, my question: Does anyone have any idea what is happening? I would greatly appreciate all thoughts. Quote
BIGAL Posted November 8, 2021 Posted November 8, 2021 Did you contact Lee ? He has a contact on his web site. Just a random guess are you running another Lee-mac program then going back to ms2ps ? May be reloading a defun making it slightly different. Quote
JerryFiedler Posted November 8, 2021 Author Posted November 8, 2021 Thanks BigAl. I do run several of Lee's programs and use lots of his tidbits of code from all his forum posts. I did not want to impose on him by contacting him directly and he is often on this site. I have thought about the clashing of functions and I am still looking through all my routines to see if there are any. The most likely routines are the ones for vector/matrix manipulation. In that regard I localized the three or four functions that ms2ps use. That should keep them clean since they would be defined each time ms2ps is called. That did not fix my problem. Quote
mhupp Posted November 9, 2021 Posted November 9, 2021 Did this happen before the mod? Maybe change this to clear the SS even tho entde is clearingit out to. gc to clear memory. (defun EraseMS2PS () (foreach ent (vl-remove-if 'listp (mapcar 'cadr (ssnamex SS))) (entdel ent) ) (setq ss nil) (gc) ) Quote
JerryFiedler Posted November 9, 2021 Author Posted November 9, 2021 Thanks mhupp. Yes the problem I describe above predates your previous help. I verified that by running Lee's program fresh off his site. All the testing/debugging I am doing now is just stand-alone ms2ps since it is easier to test than my complete routine. Clearing my global selection set is not an issue since it is not in Lee's program. I have to look up (gc) . that's new to me. Quote
mhupp Posted November 9, 2021 Posted November 9, 2021 6 minutes ago, JerryFiedler said: I have to look up (gc) . that's new to me. http://docs.autodesk.com/ACD/2013/ENU//index.html?url=files/GUID-6CABB3AF-9BED-4237-8A44-D36123246BF4.htm,topicNumber=d30e614985 Quote
JerryFiedler Posted November 11, 2021 Author Posted November 11, 2021 Here is a progress update: I have been looking at this problem for several days and this is what I have found. My template drawing consists of model space, of course, and a single layout, "SK", which contains nothing but my "title block" block. My normal work process is to copy the "SK" layout to start each new sketch. These will be sequentially numbered. This has worked for decades with no issues whatsoever. Lee Mac's ms2ps program works correctly on "SK". It also works correctly on the FIRST copy which I have named "SK (1)". The program fails to work on each subsequent layout, that is, "SK (2)", "SK (3)" etc... which are all copies of "SK". I thought something might be squirrelly with my layout template so I created new default layouts using the "+" icon in the layout bar. These are automatically labelled "Layout1" with the copies labelled "Layout1 (2)" etc. I get the same results, that is, the program ms2ps works for "Layout1" and "Layout1 (2)" which is the first copy, but fails with subsequent copies. I can go back and forth among the layouts and the program always works correctly on the original layout and the first copy; whether it is my "SK" layouts or Acad default layouts. This makes me think there is something in the layout properties that cause the problem. Layout properties are way beyond my knowledge but I will keep searching the net. If I fix this I will certainly post my solution. Quote
BIGAL Posted November 12, 2021 Posted November 12, 2021 Maybe 2 things is mview locked ? If so unlock. Do a small pan before running this will force a regen of the objects inside the mview. Quote
JerryFiedler Posted November 12, 2021 Author Posted November 12, 2021 Bigal Prior to your post I too thought lock/unlock may be an issue. However after testing it proved not to matter. Same results either way. I will try regen tomorrow morning when I am back on my computer. Thanks for your thoughts. Quote
JerryFiedler Posted November 12, 2021 Author Posted November 12, 2021 In response to BigAl's regen comment: Regen, Regenall nor (redraw) had any effect on the issue. For this thread I will call the viewports that do not draw the copied objects in their correct locations as "broken". This morning I went to a layout that contained only broken viewports. I simply copied a broken VP and, lo and behold, ms2ps worked exactly right on this copied VP. I did this several times and all the copies of broken VP's worked!! The Autodesk documentation for REGEN states it "Recomputes the locations and visibility for all objects in the current viewport". This seemed to be what I needed to happen but that particular command did not fix the broken VP's. I have to believe that something ms2ps is looking at in the object or viewport properties is getting bad information. The broken VP's always offset, and sometimes rescale, the objects. It seems to me to be a problem with the data given to the transformation coding in ms2ps. Quote
JerryFiedler Posted November 15, 2021 Author Posted November 15, 2021 After several more days of trouble-shooting I have not been able to determine why ms2ps does not consistently work. I wanted to use ms2ps as a subroutine in a lisp I was creating. Instead of calling ms2ps I am now using the following code. These half dozen lines do the work of approximately fifty lines of matrix math in ms2ps. Using CHSPACE has proved to be consistent regardless of which layout or viewport you are in. I have my routine working so I am passing this along only for information and discussion. ; Copy the selected objects to paperspace. ; "LM:ssget" code by Lee Mac (McDonnell) www.lee-mac.com ; "Copy" code by Greg Battin - Autocadtips1.com - Oct 2011 (setq MSsel (LM:ssget "Select edges of object to be broken." '(((410 . "Model"))))) (repeat (setq i (sslength MSsel)) (ssadd (vlax-vla-object->ename (vla-copy (vlax-ename->vla-object (ssname MSsel (setq i (1- i)))))) PSsel ) ) (command "_.chspace" PSsel "" "") Quote
mhupp Posted November 15, 2021 Posted November 15, 2021 Could you post a pic of whats its doing? and maybe a blank drawing too. Quote
JerryFiedler Posted November 15, 2021 Author Posted November 15, 2021 mhupp, here is a drawing. To run ms2ps you must first activate the viewport on the layout. All of the sketches are simple copies of the template "SK". Program works on the original "SK" as well as "SK (1)" but not on any other copy. Very strange! TESTv3_ms2ps.dwg Quote
mhupp Posted November 15, 2021 Posted November 15, 2021 I think I have fixed it. It was selecting the last used viewport to calculate the angel, north, and scale. Before you update the lisp run one last test on my drawing to see what I am talking about. go to tab SK (2) and activate the viewport. pan, zoom, make changes to the viewport some how. go back to paper space and switch to SK Activate the viewport in SK and use MS2PS. It will import the entiys from model space using SK (2) Update line 55 (setq enx (entget (ssname (ssget "_X" (list '(0 . "VIEWPORT") (cons 69 (getvar 'cvport))(cons 410 (getvar 'ctab)))) 0)) This will select the correct Viewport to run the calculations on. TESTv3_ms2ps.dwg 1 Quote
BIGAL Posted November 15, 2021 Posted November 15, 2021 This may be useful use where there is multiple viewports. (setq cspace (cdr (assoc 69 (entget (car (entsel "\nPick viewport")))))) (command "Mspace") (setvar 'cvport cspace) Quote
mhupp Posted November 16, 2021 Posted November 16, 2021 (edited) 2 hours ago, BIGAL said: This may be useful use where there is multiple viewports. (setq cspace (cdr (assoc 69 (entget (car (entsel "\nPick viewport")))))) (command "Mspace") (setvar 'cvport cspace) It wasn't that there were multiple viewports. Its that the 69 value isn't unique. Tab1 create a viewport its 69 value is 2 create another viewport its 69 value is 3 Tab2 create a viewport its 69 value isn't 4 its 2 again. had to add the (cons 410 (getvar 'ctab)) to say Select viewport (69 . 2) (410 . "Tab2") Edited November 16, 2021 by mhupp Quote
JerryFiedler Posted November 16, 2021 Author Posted November 16, 2021 Thank you both. I will give mhupp's correction a try tomorrow when I am back on my computer. As I said earlier I am calling ms2ps from my routine. My routine selects the desired VP and activates it, then calls ms2ps. After reviewing line 55 it is clear that the VP it is extracting data from will not necessarily be the one that I selected. Such a small thing had me stumped for days. Thank you mhupp for finding the needle in the haystack! Quote
BIGAL Posted November 16, 2021 Posted November 16, 2021 (getvar 'cvport ) will return 1 when in pspace if ran on its own, else returns the current viewport number if in mspace. Quote
JerryFiedler Posted November 16, 2021 Author Posted November 16, 2021 mhupp, Your solution to add the current tab variable to the ssget filter was the right answer. Again, thank you very much for your help. I want to add just one thing. I followed your instructions but when I went back to SK and ran ms2ps it actually still worked. However, when I created SK (3) and added a VP the objects were placed as oriented in the SK (2) VP. So that clearly demonstrates the problem. I think opening AutoCAD reset system variables so you don't see the problem until you create a new layout. Whatever, it simply does not matter. Quote
BIGAL Posted November 17, 2021 Posted November 17, 2021 If you look at what I posted you can actually be in mspace in a viewport but select another and it will jump to that viewport making it current. There is possibly something in the code that needs to be changed to recognise current vport. I had a similar problem with multiple viewports and some code. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.