Author Topic: viewport number -1 . Why ?  (Read 2992 times)

0 Members and 1 Guest are viewing this topic.

bikelink

  • Guest
viewport number -1 . Why ?
« on: February 12, 2009, 06:50:55 AM »
this code run correctly...only if the viewport is more bigger in Y than 20 or somthing simlar... ! :-o :-o
Why ? the objectid is ok, the handle is ok.,..just Number stay -1! but only if the viewport is little in Y side..
You guess an A3 format...
in x 413 in y 20 ...NUmber > 0
in x 413 in y 10.8 ...NUmber -1
Thanks in advance...i need help this time...any suggestion will be appreciated.!


 
Code: [Select]
public static ObjectId MakeViewport(Document d, Point2d s)
        {
            ObjectId viewportID = ObjectId.Null;
            Database db = d.Database;
            if (B2UtilCad.B2Editor.b2Editor.IsPaperSpace(db) == false)
            {
                System.Windows.Forms.MessageBox.Show("you're not in Paper Space");
                return viewportID;
            }
            using (DocumentLock l = d.LockDocument())
            {
                using (Transaction t = d.Database.TransactionManager.StartTransaction())
                {

                    Point3d pt1 = new Point3d(0, 0, 0);
                    Point3d pt2 = new Point3d(s.X, s.Y, 0);


                    Viewport vport = new Viewport();
                    vport.Height = (double)Math.Abs(pt1.Y - pt2.Y);
                    vport.Width = (double)Math.Abs(pt1.X - pt2.X);
                    // da controllare la sottrazione dei due vettori
                    //Vector3d ptc = pt2.GetAsVector().Subtract(pt1.GetAsVector());
                    vport.CenterPoint = new Point3d(pt2.X / 2, pt2.Y / 2, 0);
                    vport.SetDatabaseDefaults();


                    BlockTable bt = (BlockTable)t.GetObject(db.BlockTableId, OpenMode.ForWrite, false);
                    BlockTableRecord blkRec = (BlockTableRecord)t.GetObject(bt[BlockTableRecord.PaperSpace], OpenMode.ForWrite, false);
                    blkRec.AppendEntity(vport);
                    vport.On = true;      // can't be set until after it is added to database
                   
                    vport.SnapOn = false;
                   
                    vport.Color = Autodesk.AutoCAD.Colors.Color.FromColor(System.Drawing.Color.Red);
                    int vpNum = vport.Number;
                    t.AddNewlyCreatedDBObject(vport, true);
                    vport.UpdateDisplay();
                    t.Commit();
                    viewportID = vport.ObjectId;
                }
                return viewportID;
            }


        }

added code tags
« Last Edit: February 12, 2009, 08:21:45 AM by Daniel »

bikelink

  • Guest
Re: viewport number -1 . Why ?
« Reply #1 on: February 12, 2009, 09:48:16 AM »
the zoom in paper space is the problem. :pissed: :pissed: :pissed: :pissed: :pissed: :pissed:
bleah!

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2138
  • class keyThumper<T>:ILazy<T>
Re: viewport number -1 . Why ?
« Reply #2 on: February 12, 2009, 05:02:31 PM »
so, the answer to the problem is ??

... or was your problem what you thought it was ??
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.

bikelink

  • Guest
Re: viewport number -1 . Why ?
« Reply #3 on: February 13, 2009, 01:48:33 AM »
If I look from distant the layout  in paperspace and I build a little viewport, (don't ask me why and the scale..) autocad return -1 in number property.
If I perform a zoom similar to size of viewport that i'm going to build...also with a very very little size autocad return > 1 ;)
This is a big bug...IMHO. 
The behavior of this property is very very strange, 'cause you see the viewport..in your drawing. in the first case in code you'havent the right setting...in number property .
at the stop of your code...if you ask autocad the entget (via lisp example..) of this viewport you see a right setting! but when you run the code the build this little viewport, if you don't have a zoom in paper space...it pass from 0 to -1 until your code is terminated
and the docs in arx/managed about viewport is pure fantasy...it's talks about property that doesn't exist. Bad, very very bad..autodesk.
Believe  if I said that i'm going crazy to resolve this... :ugly: :ugly:

Bryco

  • Water Moccasin
  • Posts: 1883
Re: viewport number -1 . Why ?
« Reply #4 on: February 13, 2009, 10:00:35 AM »
from help-Gets the viewport ID number. This is the number that is reported by the AutoCAD CVPORT system variable when the viewport is the current viewport in the AutoCAD editor. If the viewport is inactive, -1 is returned.
The number is describing the state of the vp

bikelink

  • Guest
Re: viewport number -1 . Why ?
« Reply #5 on: February 13, 2009, 04:26:27 PM »
I knew of course.. but isn't the trouble. You can make active the viewport via number...but the number exists  property of your viewport.
example : if you have 3 viewports in your layout and you check via entget the number you see 2,3,4 as field...but just on is current (of course)
I'm sure of this... and if you try to run the code and build different viewport with very small size you can verify this...
if you build a little viewport in a layouy saw from distant the viewport is -1.
the same code with the same layout zoomed ...return > 1