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

zoom an object and text

3 REPLIES 3
Reply
Message 1 of 4
hoyin0820
385 Views, 3 Replies

zoom an object and text

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

3 REPLIES 3
Message 2 of 4
matus.brlit
in reply to: hoyin0820

what do you mean by "zoom object"?

Message 3 of 4
Hallex
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
Message 4 of 4
hoyin0820
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)

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