.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

viewport Number -1 ?

5 REPLIES 5
Reply
Message 1 of 6
bikelink
849 Views, 5 Replies

viewport Number -1 ?

Hi, I have created 2 viewport in my layout via code.
1 of this , has property Number -1. No one error during creation ...but it's have number -1. Object id is valid.
Then when i try to get it in writemode an error occurred. Any suggestion ?
5 REPLIES 5
Message 2 of 6
bikelink
in reply to: bikelink

If the size of viewport is >= of layout dimension -1 si returned
as soon you have created a viewport with dimension inside layout the number increase...
example:

1 layout 210x297
creation viewport with same size--> -1 returned
creation viewport with same size--> -1 returned
creation viewport size 205x290 . --> 4 or 5.


Well, the viewport internal is numbered but autocad don't show us the index , until he (you..) drawing inside the layout.
I think that is a bug. If I need to create a viewport outside the layout (and autocad allows this.) autocad must to number all the viewports
created. Please tell me if i wrong..
Message 3 of 6
bikelink
in reply to: bikelink

isn't this...yet.

I try to make a viewport inside the layout..with height 10 in A3. It's very little viewport...and autocad return -1.

and the viewport is drawing in paper space

if the size Y-height increases 20 (example), return positive number and of course the viewport is ok.

there are a minimum size to build a viewport in paperspace ?





in my viewport buildin snapon =false..

I don't know where can i find a solution..





that's my code:

using (DocumentLock l = d.LockDocument())

{

using (Transaction t = Application.DocumentManager.MdiActiveDocument.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);

{color:#ff0000}int vpNum = vport.Number;{color}

t.AddNewlyCreatedDBObject(vport, true);

t.Commit();

viewportID = vport.ObjectId;

}

return viewportID;

}









why the number is -1 when the viewport is created with a small size in y dimension ?

the same code if i try to build a viewport with Height 20 instead of 10 return vport.number > 0
Message 4 of 6
bikelink
in reply to: bikelink

OK....i don't understood ...the zoom in paper space is the base of my trouble.
if you look from distant the layout, the viewports with a little size aren't numbered!
if you perform a zoom in paper space..or better a zoom with the angle of your viewport in creation...then the number will be correct.


the right sequence is
create layout
zoom extension in paper space (but if you have an A0/A1 and some little viewport this couldn't be are enough)
better zoom on your size viewport.
creation viewport. the number is right.

thanks autocad...for this joke.. 🙂
Message 5 of 6
Rob.O
in reply to: bikelink

Excellent!

 

Sorry to bring an old thread back from the dead, but I just ran into this exact issue!

 

My newly created viewports were comining up with the number of -1.  After doing a zoom extents on the new layout (prior to creating the new viewports), the viewports are numbered properly and I no longer get an error!!

 

Thanks for figuring this out bikelink!

Message 6 of 6
cincir
in reply to: bikelink

İ am confused a little. arent ViewPortTableRecords member of ViewPortTable ?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost