.NET

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

zoom an object and text

166 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 (150 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 (130 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 (105 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)

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community