Recent Posts

Pages: 1 ... 3 4 [5] 6 7 ... 10
AutoLISP (Vanilla / Visual) / Locked layer causes interface IAcadSelectionSet error
« Last post by sovby on September 28, 2020, 03:25:24 PM »
I have a routine that changes some colors on some entities and wblocks them out using a window selection. I found out that if there is a locked layer in the selection set i get this message.

** Error: Automation Error. Calling method Clear of interface IAcadSelectionSet failed **
Cannot invoke (command) from *error* without prior call to (*push-error-using-command*).
Converting (command) calls to (command-s) is recommended.

Has anyone had anything similar to this? If i unlock the layer everything is fine so it has something to do with the locked layer as far as i can tell
AutoLISP (Vanilla / Visual) / Re: LISP Dot Net Wrapper
« Last post by jtoverka on September 28, 2020, 12:19:43 PM »
I have found a better implementation without calling the DotNetWrapper every time.
Code: [Select]
(defun JO:Netload (files / *error* cmdecho)
  (defun *error* (msg / )
    (and cmdecho (setvar 'cmdecho cmdecho))
    (princ "; error: ")
    (princ msg)
  (defun JO:*error* (msg / *error*)
    (defun *error* (msg)
    (princ "\n; error: ")
    (princ msg)
  (setq cmdecho (getvar 'cmdecho))
  (setvar 'cmdecho 0)
  (foreach file files
    (command-s "NETLOAD" file)
  (setvar 'cmdecho cmdecho)
  (setq cmdecho nil)
  (vl-acad-defun 'JO:*error*)

Call with:
Code: [Select]
(JO:Netload '("C:/Users/jtoverka/Desktop/NetDBX Library.dll"))

.NET function:
Code: [Select]
/// <summary>
/// Invokes a Lisp error message.
/// </summary>
/// <param name="message"></param>
/// <remarks>
/// This will trigger the end of the running lisp function.
/// </remarks>
public static void ThrowLispError(string message)
        using ResultBuffer error = new ResultBuffer(
            new TypedValue((int)LispDataType.Text, "JO:*error*"),
            new TypedValue((int)LispDataType.Text, message));

        ResultBuffer rtn = Application.Invoke(error);
    catch (System.Exception e)
        Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
        ed.WriteMessage($"\n; error: {message}\n");
        ed.WriteMessage($"\n; Unhandled LISP Error Exception: {e.Message}\n");
As long as the .NET code invokes the "JO:*error*" autolisp function.

The only way to truly improve upon this implementation is the ability to create and evaluate lambda Lisp functions in .NET without the need for vl-acad-defun. If anyone knows how to do this, or something equivalent, please share  :-)
AutoLISP (Vanilla / Visual) / Re: LISP Dot Net Wrapper
« Last post by jtoverka on September 28, 2020, 12:06:23 PM »
I kind of wish there was a way to get more attention/credit to all the nifty code snippets provided here... for free none the less.

Agreed. I would really prefer a like button, with the ability to rank, sort, and search code by the amount of likes it gets.
AutoLISP (Vanilla / Visual) / Re: LISP Dot Net Wrapper
« Last post by Rustabout on September 27, 2020, 10:04:37 AM »
Much of the amazing stuff in the "show your stuff" threads tend to get hidden. I only recently browsed those threads. It was funny because I recall almost being in tears trying to get an AutoLISP code to work (prevailed none the less) only to see the exact code in the "show your stuff"... just a better version.

I kind of wish there was a way to get more attention/credit to all the nifty code snippets provided here... for free none the less.
BricsCAD Users / For any of you BricsCAD aficionados: BricsCAD Platinum is on sale.
« Last post by Rustabout on September 26, 2020, 03:01:53 PM »
Bricsys doesn't have sales all that often.

I was kind of hoping to see more sales (in general, not just with Bricsys), as there might be no time better to try and gain market share. The drawback to having a sale is that you kind of burn people who've just bought their licenses (but you could offer-up something in return like a cheap upgrade).

If I were looking for the functionality of Platinum I would probably buy it right now. I really only need the functionality of the Classic version however. Hence why I check their site now and then for sales.
CAD General / Re: Batch operations on multiple files
« Last post by framednlv on September 26, 2020, 02:02:05 PM »
This seems to work:
Code: [Select]
if /I [%~x1]==[.DWG] (echo "[%count%/%argc%]: Processing... %~f1" ) else (echo "[%count%/%argc%] skipping %~f1" )
if /I [%~x1]==[.DWG] (call "C:\Program Files\Autodesk\AutoCAD 2021\accoreconsole.exe" /i "%~f1" /s %script% /l en-US >"C:\temp\cleanup.log")

There is one problem I found.  If any of the file names or folders have the '&' character it doesn't work.

.NET / multiple plot to pdf
« Last post by daboho on September 26, 2020, 07:31:06 AM »
 i has try change code from this link
i want plot multiple pdf by select block reference as border
this is my code
Code: [Select]
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.PlottingServices;
using Autodesk.AutoCAD.Geometry;
using System.Runtime.InteropServices;
using System;
using System.Collections.Generic;

namespace PlottingApplication
    public class SimplePlottingCommands
        [DllImport("accore.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "acedTrans")]
        static extern int acedTrans(double[] point, IntPtr fromRb, IntPtr toRb, int disp, double[] result);
        static public void WindowPlot()
            Document doc = Application.DocumentManager.MdiActiveDocument;
            Editor ed = doc.Editor;
            Database db = doc.Database;
            //PromptPointOptions ppo = new PromptPointOptions("\nSelect first corner of plot area: ");
            //ppo.AllowNone = false;
            //PromptPointResult ppr = ed.GetPoint(ppo);
            //if (ppr.Status != PromptStatus.OK) return;

            //PromptCornerOptions pco =new PromptCornerOptions("\nSelect second corner of plot area: ",first);
            //ppr = ed.GetCorner(pco);
            //if (ppr.Status != PromptStatus.OK) return;
            int n = 1;
            var pso = new PromptSelectionOptions();
            pso.MessageForAdding = "\nsilahkan select All :";
            var psr = ed.GetSelection(pso);
            if (psr.Status != PromptStatus.OK) return;
            var dic = new Dictionary<Point3d, Point3d>();
            using (var tr = db.TransactionManager.StartTransaction())
                short bgPlot = (short)Application.GetSystemVariable("BACKGROUNDPLOT");
                //set the BACKGROUNDPLOT = 0 temporarily.
                Application.SetSystemVariable("BACKGROUNDPLOT", 0);
                foreach (SelectedObject ss in psr.Value)
                    var br = ss.ObjectId.GetObject(OpenMode.ForRead) as BlockReference;
                    if (br.Bounds.HasValue)
                        var extents = br.Bounds;
                        var ext1 = extents.Value.MinPoint;
                        var ext2 = extents.Value.MaxPoint;
                        dic.Add(ext1, ext2);

                if (dic.Count == 0) return;
                // Transform from UCS to DCS
                Point3d first; Point3d second;
                foreach (var item in dic)
                    first = item.Key;
                    second = item.Value;
                    ResultBuffer rbFrom = new ResultBuffer(new TypedValue(5003, 1)), rbTo = new ResultBuffer(new TypedValue(5003, 2));
                    double[] firres = new double[] { 0, 0, 0 };
                    double[] secres = new double[] { 0, 0, 0 };
                    // Transform the first point...
                    acedTrans(first.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, firres);
                    // ... and the second
                    acedTrans(second.ToArray(), rbFrom.UnmanagedObject, rbTo.UnmanagedObject, 0, secres);
                    // We can safely drop the Z-coord at this stage
                    Extents2d window = new Extents2d(firres[0], firres[1], secres[0], secres[1]);

                    // We'll be plotting the current layout
                    BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForRead);
                    Layout lo = (Layout)tr.GetObject(btr.LayoutId, OpenMode.ForRead);
                    // We need a PlotInfo object
                    // linked to the layout
                    PlotInfo pi = new PlotInfo();
                    pi.Layout = btr.LayoutId;
                    // We need a PlotSettings object
                    // based on the layout settings
                    // which we then customize
                    PlotSettings ps = new PlotSettings(lo.ModelType);
                    // The PlotSettingsValidator helps
                    // create a valid PlotSettings object
                    PlotSettingsValidator psv = PlotSettingsValidator.Current;
                    // We'll plot the extents, centered and
                    // scaled to fit
                    psv.SetPlotWindowArea(ps, window); psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Window);
                    psv.SetUseStandardScale(ps, true);
                    psv.SetStdScaleType(ps, StdScaleType.ScaleToFit);
                    psv.SetPlotCentered(ps, true);
                    // We'll use the standard DWF PC3, as
                    // for today we're just plotting to file
                    psv.SetPlotConfigurationName(ps, "DWG To PDF.pc3", "ISO_full_bleed_A3_(420.00_x_297.00_MM)");
                  //  psv.SetPlotConfigurationName(ps,"DWF6 ePlot.pc3", "ANSI_A_(8.50_x_11.00_Inches)");
                    // We need to link the PlotInfo to the
                    // PlotSettings and then validate it
                    pi.OverrideSettings = ps;
                    PlotInfoValidator piv = new PlotInfoValidator();
                    piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled;
                    // A PlotEngine does the actual plotting
                    // (can also create one for Preview)
                    if (PlotFactory.ProcessPlotState == ProcessPlotState.NotPlotting)
                        PlotEngine pe = PlotFactory.CreatePublishEngine();
                        using (pe)
                            // and allow thej user to cancel
                            PlotProgressDialog ppd = new PlotProgressDialog(false, 1, true);
                            using (ppd)
                                ppd.set_PlotMsgString(PlotMessageIndex.DialogTitle, "Custom Plot Progress");
                                ppd.set_PlotMsgString(PlotMessageIndex.CancelJobButtonMessage, "Cancel Job");
                                ppd.set_PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage, "Cancel Sheet");
                                ppd.set_PlotMsgString(PlotMessageIndex.SheetSetProgressCaption, "Sheet Set Progress");
                                ppd.set_PlotMsgString(PlotMessageIndex.SheetProgressCaption, "Sheet Progress");
                                ppd.LowerPlotProgressRange = 0;
                                ppd.UpperPlotProgressRange = 100;
                                ppd.PlotProgressPos = 0;
                                // Let's start the plot, at last
                                ppd.IsVisible = true;
                                pe.BeginPlot(ppd, null);
                                // We'll be plotting a single document
                                pe.BeginDocument(pi, doc.Name, null, 1, true, "c:\\test-output" + n.ToString());
                                // Which contains a single sheet
                                ppd.LowerSheetProgressRange = 0;
                                ppd.UpperSheetProgressRange = 100;
                                ppd.SheetProgressPos = 0;
                                PlotPageInfo ppi = new PlotPageInfo();
                                pe.BeginPage(ppi, pi, true, null);
                                [color=red][b]pe.BeginGenerateGraphics(null);[/b][/color] // [color=red]problem in this part [/color]
                                // Finish the sheet
                                ppd.SheetProgressPos = 100;
                                // Finish the document
                                // And finish the plot
                                ppd.PlotProgressPos = 100;
                        ed.WriteMessage("\nAnother plot is in progress.");
                Application.SetSystemVariable("BACKGROUNDPLOT", bgPlot);


CAD General / Re: Unexpected vector ->
« Last post by MickD on September 25, 2020, 07:38:39 PM »
No sweat MP, just a small vent :)
Stay well!
AutoLISP (Vanilla / Visual) / Re: Sheet Index
« Last post by steve.carson on September 25, 2020, 12:09:32 PM »
Oh, yeah, forgot to mention there is always an error displayed at the command line when running the sstable function. I was never able to track it down, but it runs and completes and creates the table.

AutoLISP (Vanilla / Visual) / Re: Sheet Index
« Last post by steve.carson on September 25, 2020, 12:05:20 PM »
Using the great code by MP for the DST->XML functions, by Lee Mac for the Table and DCL functions, and J. Szewczak for the XML functions, I put together the attached sheetset functions, some more useful than others. I'm sure anything written by me could be improved. I think this was the second time I played with DCL, so there was a lot of guess-and-check going on.

I think the most useful function in here is the "sstable" function that lets you create a regular autocad table from multiple dst files. This is handy for when you have separate dst's for each discipline in a project. I tried to mimic the built in method to create a sheet list table from the SSM, where you can specify the column headings for whatever property you want in the table. It stores an xrecord in the drawing, and uses it as defaults for the next time you run it. It's not very fast, but much faster than built in methods. Our projects are pretty big (Ports and Harbors, Marine structures).

There is also a function to index a sheet property ("indexss"), which is handy for the X in "sheet X of XX".

Hope for can find it useful!

Big thanks to MP, Lee Mac, and J. Szewczak!

Pages: 1 ... 3 4 [5] 6 7 ... 10