repeat insert block - while lo
Hi everybody!This is my first post ever, I hope of some feedback...
I am not an expert in lisp, but with a lot of searching I can manage to find and modify what I need.
But in this case I don understand why in this code (which repeats inserting one block until user hits enter) the block is not visible on crosshair:
(defun c:MyBlock (/ pt)
(while (setq pt (getpoint "\nPick Insertion point."))
(command "-insert" "BlockName" "_non" pt "" pause)
)
(princ)
)
I have made also one with repeat, and then is the block visible on crosshair:
(repeat 3000
(princ "\nPick Insertion point.")
(command "insert" "BlockName" pause "" "" "")
);end repeat
But I would prefer not to use ESC to break repeat (before it makes the same 3000 times), as an user.
Thanks very much,
and have a nice day! Hi,
the block isn't visible on the crosshair because the point is specified in the (getpoint ...) expression which is evaluated before the (command "_insert"... ) statement.
Hi Gile,
Thanks!
So there is no other way to see the block except with "repeat"? Here's a way using grread. Inconvenient: you can't use osnaps.
(defun c:MyBlock (/ InsertBlock elst gr loop) (defun InsertBlock () (entmake '((0 . "INSERT") (10 0.0 0.0 0.0) (2 . "BlockName") ) ) ) (InsertBlock) (setq elst (entget (entlast)) loop T) (while (and (setq gr (grread T 4 0)) loop) (cond ((= (car gr) 5) (entmod (subst (cons 10 (cadr gr)) (assoc 10 elst) elst)) ) ((= 3 (car gr)) (InsertBlock) (setq elst (entget (entlast))) ) (T (entdel (entlast)) (setq loop nil)) ) ) (princ)) Still have to hit escape to exit...
(defun c:Test (/) (while t (command "_.-insert" "BlockName" "_s" 1.) (princ "\nSpecify insertion point: ") (command PAUSE) (princ "\nSpecify rotation: ") (command PAUSE) ) (princ)) Thanks Gile,
For your time, but without "osnap" I am dead man! Thanks Alan,
For your time too, I have to consider ESC as a slolution.
Have a nice day! Here's a .NET solution:
Command: MULTINSERT
Prompt the user for a block name (or a dwg name, have to specify the full path if the the file isn't in AutoCAD search path),
displays the bloc during insert,
allows osnaps using,
hit Enter or Space or right click to break the loop.
C# code
using Autodesk.AutoCAD.ApplicationServices;using Autodesk.AutoCAD.DatabaseServices;using Autodesk.AutoCAD.EditorInput;using Autodesk.AutoCAD.Geometry;using Autodesk.AutoCAD.Runtime;namespace MultiInsertSample{ public class MyBlockClass { class BlockJig : EntityJig { BlockReference m_blkRef; Point3d m_insPt; public BlockJig(BlockReference br) : base(br) { m_insPt = br.Position; m_blkRef = br; } protected override SamplerStatus Sampler(JigPrompts prompts) { JigPromptPointOptions jigOpts = new JigPromptPointOptions(); jigOpts.UserInputControls = (UserInputControls.Accept3dCoordinates | UserInputControls.NullResponseAccepted); jigOpts.Message = "\nEnter insert point: "; PromptPointResult ppr = prompts.AcquirePoint(jigOpts); if (m_insPt == ppr.Value) return SamplerStatus.NoChange; else m_insPt = ppr.Value; return SamplerStatus.OK; } protected override bool Update() { m_blkRef.Position = m_insPt; return true; } } public void MultiInsert() { Document doc = Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; PromptStringOptions opts = new PromptStringOptions("\nEnter block name: "); PromptResult pr = ed.GetString(opts); if (pr.Status != PromptStatus.OK) return; Transaction tr = doc.TransactionManager.StartTransaction(); using (tr) { BlockTable bt = (BlockTable)tr.GetObject(db.BlockTableId, OpenMode.ForRead); ObjectId blockId = ObjectId.Null; string name = pr.StringResult; if (bt.Has(name)) blockId = bt; else { try { string filename = HostApplicationServices.Current.FindFile( name.EndsWith(".dwg") ? name : name + ".dwg", db, FindFileHint.Default); using (Database source = new Database(false, true)) { source.ReadDwgFile(filename, System.IO.FileShare.None, false, null); blockId = db.Insert(name, source, false); } } catch { ed.WriteMessage("\nBlock not found."); return; } } while (pr.Status == PromptStatus.OK) { Point3d pt = new Point3d(0, 0, 0); using (BlockReference br = new BlockReference(pt, blockId)) { BlockJig entJig = new BlockJig(br); pr = ed.Drag(entJig); if (pr.Status == PromptStatus.OK) { BlockTableRecord btr = (BlockTableRecord)tr.GetObject(bt, OpenMode.ForWrite); btr.AppendEntity(br); tr.AddNewlyCreatedDBObject(br, true); doc.TransactionManager.QueueForGraphicsFlush(); } } } tr.Commit(); } } }}
MultInsert.zip You're welcome. It's about the best you can get, using LISP.
Nice work, Gile! Thanks Gile,
But how can I start it? What shall I do with "MultiInsertSample.dll" ?
I am not so good, guys! I have never seen something like that!
页:
[1]
2