.NET

Reply
Contributor
hoyin0820
Posts: 15
Registered: ‎08-09-2013
Message 1 of 4 (191 Views)

zoom an object and text

191 Views, 3 Replies
09-09-2013 01:53 AM

i want to zoom object by its properties, such as  i want to zoom the object was using 0.13mm lineweights or zoom the text which was using 3mm testheight

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 2 of 4 (175 Views)

Re: zoom an object and text

09-09-2013 05:01 AM in reply to: hoyin0820

what do you mean by "zoom object"?

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 4 (155 Views)

Re: zoom an object and text

09-09-2013 01:10 PM in reply to: hoyin0820

Try this code snip, change entity types in selection filter

on whatever you neeed:

     using System;
    using System.Collections.Generic;
    using System.Linq;
    using Autodesk.AutoCAD.ApplicationServices;
    using Autodesk.AutoCAD.DatabaseServices;
    using Autodesk.AutoCAD.EditorInput;
    using Autodesk.AutoCAD.Geometry;
    using Autodesk.AutoCAD.Runtime;
   //---------------------------------------------------------------------------------------------//
            public void ZoomWindow(Document doc, Point2d minpt, Point2d maxpt)
            {
                ViewTableRecord view = new ViewTableRecord();
                view.CenterPoint = (minpt + (maxpt - minpt) / 2.0);
                view.Height = (maxpt.Y - minpt.Y);
                view.Width = (maxpt.X - minpt.X);
                doc.Editor.SetCurrentView(view);
                doc.Database.UpdateExt(true);
            }
            [CommandMethod("seltest")]
            public void testSelection()
            {
                var doc = acApp.DocumentManager.MdiActiveDocument;
                var db = doc.Database;
                var ed = doc.Editor;
                PromptSelectionOptions pso = new PromptSelectionOptions();

                TypedValue[] filter = new TypedValue[] {
                    new TypedValue((int)DxfCode.LayoutName,Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("CTAB")),
                    new TypedValue((int)DxfCode.Operator,"<or"),
                    new TypedValue((int)DxfCode.Operator,"<and"),
                    new TypedValue(0, "TEXT,MTEXT"),
                    new TypedValue((int)DxfCode.TxtSize,3.0),
                    new TypedValue((int)DxfCode.Operator,"and>"),
                    new TypedValue((int)DxfCode.Operator,"<and"),
                    new TypedValue(0, "*LINE,CIRCLE,ARC,RAY,XLINE,MLINE,*LEADER,*DIM*,ETC"),
                    new TypedValue((int)DxfCode.LineWeight, 0.13),
                    new TypedValue((int)DxfCode.Operator,"and>"),
                    new TypedValue((int)DxfCode.Operator,"or>")};

                SelectionFilter sf = new SelectionFilter(filter);
                PromptSelectionResult res = ed.SelectAll(sf);

                if (res.Status != PromptStatus.OK)

                    return;

                SelectionSet sset = res.Value;

                ed.WriteMessage("\nSelected {0} objects", sset.Count);

                using (Transaction tr = db.TransactionManager.StartTransaction())
                {
                    BlockTableRecord btr = tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite) as BlockTableRecord;
                    try
                    {


                        ObjectId[] ids = sset.GetObjectIds();

                        if (ids.Length == 0) return;

                        var ents = from id in ids
                                   where id != null
                                   select tr.GetObject(id, OpenMode.ForRead);

                        var minx = (from n in ents
                                    where n != null
                                    select ((Entity)n).GeometricExtents.MinPoint[0]).Min();

                        var maxx = (from n in ents
                                    where n != null
                                    select ((Entity)n).GeometricExtents.MaxPoint[0]).Max();

                        var miny = (from n in ents
                                    where n != null
                                    select ((Entity)n).GeometricExtents.MinPoint[1]).Min();
                        var maxy = (from n in ents
                                    where n != null
                                    select ((Entity)n).GeometricExtents.MaxPoint[1]).Max();

                        ZoomWindow(doc, new Point2d(minx, miny), new Point2d(maxx, maxy));

                        tr.Commit();

                    }

                    catch (Autodesk.AutoCAD.Runtime.Exception ex)
                    {
                        Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(ex.Message);
                    }
                }
            }

 

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Contributor
hoyin0820
Posts: 15
Registered: ‎08-09-2013
Message 4 of 4 (130 Views)

Re: zoom an object and text

09-10-2013 12:43 AM in reply to: Hallex

i used ur code. but those 2 codes seem do not work

i used vb.net  .

i tried acTypValAr.SetValue(New TypedValue(DxfCode.LineWeight, LineWeight.LineWeight030), 0)

acTypValAr.SetValue(New TypedValue(DxfCode.LineWeight, 30, 0)

acTypValAr.SetValue(New TypedValue(DxfCode.LineWeight, 0.3, 0)

it also do not work :'(

new TypedValue((int)DxfCode.TxtSize,3.0),
new TypedValue((int)DxfCode.LineWeight, 0.13)
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.