Recent Posts

Pages: [1] 2 3 ... 10
1
.NET / Re: Linetype scaling differs for unknown reason
« Last post by damien_conroy on May 11, 2024, 04:54:21 PM »
the code is pretty sprawling/ugly so I wouldn't know what to include, and I think this might be more of an Autocad skills problem than coding skills problem.
Simplified process for plugin:
Cleanup and prep drawing
calculate size of plot
create layout, control the size by Viewport.ViewHeight (copy paste from Kean Walmsley)
do the plugin functionality, includes drawing some new polyline 2d

here is the section where I create the new polylines, I'm offsetting open polylines so I need to find the direction by measureing a distance to another always present line. The funtionality is pretty much working unless someone has the correct non-idiot way of doing it :) my problem is is with the linetype scaling.
Code - C#: [Select]
  1. using (Transaction trans = db.TransactionManager.StartTransaction())
  2. {
  3.     try
  4.     {
  5.         BlockTable bt = trans.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
  6.         BlockTableRecord btr = trans.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
  7.  
  8.        
  9.  
  10.         foreach (ObjectId o in linesToOffset)
  11.         {
  12.             //get the polyline from the blocktable
  13.             Polyline2d ln = trans.GetObject(o, OpenMode.ForWrite) as Polyline2d;
  14.  
  15.             //test for a bad polyline
  16.             Curve curve = ln as Curve;
  17.             if (curve == null)
  18.             {
  19.                 edt.WriteMessage("\nCurve is null");
  20.                 logResults["runError"] = "True";
  21.                 logResults["comment"] = "Null curve in DoPaintLines()";
  22.                 LogMethodCompleted("DoOffset()");
  23.                 return false;
  24.             }
  25.  
  26.             Point3d profilePt = new Point3d();
  27.             Point3d plinePt = new Point3d();
  28.             Point3dCollection intersectionPoints = new Point3dCollection();
  29.  
  30.             //if the paintline is the correct distance from from the profiles
  31.             //then we find a point to indicate the correct direction to offset.
  32.             //If the offset curve touches the circle with center at a point in
  33.             //the correct direction at the correct distance then we say the offset
  34.             //is on the correct side otherwise reverse the polyline and test again.
  35.             //If test still doesn't work retry a few times
  36.             //Also adjusts polylines style
  37.  
  38.             bool offset_succeeded = false;
  39.             Int32 offset_iterations = 0;
  40.             while ((!offset_succeeded) && (offset_iterations < offset_max_iterations) && (logResults["runError"] == "False"))
  41.             {
  42.  
  43.                 if (FindTestPt(ln, ref profilePt, ref plinePt, find_test_point_iterations))
  44.                 {
  45.                     offset_amount = (offset_target * scaleFactor) - offset_begin;
  46.  
  47.                     Vector3d vec = profilePt.GetVectorTo(plinePt).GetNormal().MultiplyBy((offset_target * scaleFactor) + intersectionTolerance * 2);
  48.                     Line testLine = new Line(profilePt, profilePt.Add(vec));
  49.  
  50.                     Vector3d vec2 = profilePt.GetVectorTo(plinePt).GetNormal().MultiplyBy(offset_target * scaleFactor);
  51.                     Point3d offsetTargetPt = profilePt.Add(vec2);
  52.  
  53.                     DBObjectCollection offsetLn = ln.GetOffsetCurves(offset_amount);
  54.  
  55.                     foreach (Polyline2d off in offsetLn)
  56.                     {
  57.                         off.IntersectWith(testLine, Intersect.OnBothOperands, intersectionPoints, IntPtr.Zero, IntPtr.Zero);
  58.                         if (intersectionPoints.Count == 1)
  59.                         {
  60.                             Double intersectionDistance = intersectionPoints[0].DistanceTo(offsetTargetPt);
  61.                             if (intersectionDistance < intersectionTolerance)
  62.                             {
  63.                                 offset_succeeded = true;
  64.                             }
  65.                         }
  66.                     }
  67.  
  68.                     if (!offset_succeeded)
  69.                     {
  70.                         offsetLn = ln.GetOffsetCurves(offset_amount * -1);
  71.                         foreach (Polyline2d off in offsetLn)
  72.                         {
  73.                             intersectionPoints.Clear();
  74.                             off.IntersectWith(testLine, Intersect.OnBothOperands, intersectionPoints, IntPtr.Zero, IntPtr.Zero);
  75.                             if (intersectionPoints.Count == 1)
  76.                             {
  77.                                 Double intersectionDistance = intersectionPoints[0].DistanceTo(offsetTargetPt);
  78.                                 if (intersectionDistance < intersectionTolerance)
  79.                                 {
  80.                                     offset_succeeded = true;
  81.                                 }
  82.                             }
  83.                         }
  84.                     }
  85.  
  86.                     if (offset_succeeded)
  87.                     {
  88.                         foreach (Polyline2d acEnt in offsetLn)
  89.                         {
  90.                             btr.AppendEntity(acEnt);
  91.                             trans.AddNewlyCreatedDBObject(acEnt, true);
  92.                             //acEnt.LinetypeScale = LinetypeScale;
  93.                             //acEnt.LineWeight = lineweight;
  94.                             acEnt.ConstantWidth = 0.5 * scaleFactor;
  95.                             acEnt.Linetype = offsetLineType;
  96.                             acEnt.LinetypeScale = offsetLineTypeScale;
  97.                             acEnt.LinetypeGenerationOn = true;
  98.                         }
  99.                         if (!displayDebugHelpers)
  100.                         {
  101.                             ////////////////  DEBUG GRAPHICS  //////////////////
  102.                             //erase original paintline
  103.                             ln.Erase();
  104.                             ////////////////  DEBUG GRAPHICS END //////////////////
  105.                         }                                  
  106.                     }
  107.                     else
  108.                     {
  109.                         ln.ConstantWidth = 0.5 * scaleFactor;
  110.                         ln.Linetype = offsetLineType;
  111.                         ln.LinetypeScale = offsetLineTypeScale;
  112.                         ln.LinetypeGenerationOn = true;
  113.                     }
  114.  
  115.                     //IntersectCircle(ObjectIdCollection ProfileIDs, Point3d circleCenter, ref Point3d pt)
  116.  
  117.                     if (displayDebugHelpers)
  118.                     {
  119.                         ////////////  DEBUG GRAPHICS  //////////////////
  120.                         btr.AppendEntity(testLine);
  121.                         trans.AddNewlyCreatedDBObject(testLine, true);
  122.                         ////////////  DEBUG GRAPHICS END //////////////////
  123.                     }
  124.                 }
  125.                 else
  126.                 {
  127.                     //logResults["runError"] = "True";
  128.                     logResults["comment"] = "Failed to find testpoint";
  129.                     edt.WriteMessage("\nTestPt not found\n");
  130.                     result_paintlines_status = "PaintLineFailed"; //For testing
  131.                 }
  132.  
  133.  
  134.                 offset_iterations++;
  135.             }
  136.  
  137.             if (!offset_succeeded)
  138.             {
  139.                 //logResults["runError"] = "True";
  140.                 logResults["comment"] = "Failed after repeated tries";
  141.             }
  142.  
  143.  
  144.         }
  145.  
  146.     //doc.Editor.Regen();
  147.     trans.Commit();
  148.     }
  149.     catch (System.Exception ex)
  150.     {
  151.         //logResults["runError"] = "True";
  152.         logResults["generalException"] = ex.Message;
  153.         edt.WriteMessage("exeption: " + ex.Message + "\n");
  154.     }
  155. }
  156.  
2
.NET / Re: Linetype scaling differs for unknown reason
« Last post by kdub_nz on May 11, 2024, 04:23:26 PM »
Hi Damien,
We'd probably need to see the code you're using.

I assume you are saving the drawing after you make the changes ?

I haven't done any plotting to .png, so have no knowledge of pitfalls in that regard.

Regards,

added:
Is there any common factor for the files that fail to plot sucessfully ?
3
.NET / Linetype scaling differs for unknown reason
« Last post by damien_conroy on May 11, 2024, 10:43:45 AM »
I am using a c# plugin to do some changes to a file and then prepare a properly scaled viewport for plotting a png, then in a batch script I'm applying this to thousands of files with accoreconsole.exe where I load the file, apply the plugin, and plot.

On some files the linetypescaling isn't coming out as expected and I can't find the reason for this. LTSCALE and PSLTSCALE are the same on all files, what other settings should I be looking at?

edit: forgot to add, the linetype scaling is different after plotting from accoreconsole than it is after running the plugin in editor, that's another head scratcher for me, is it connected to the first issue? 
4
Seem to remember open a pdf direct just like this (startapp "notepad" "D:\\acadtemp\\test.lsp")

Something a simple as (command "_start" "D:\\acadtemp\\newblock-02.pdf") Worked in my Bricscad.
5
XDRX-API / [XDrX-Function(42)] string sort
« Last post by xdcad on May 10, 2024, 09:39:23 PM »
xdrx-string-logical<

Used to compare two strings in logical order. This function is typically used to sort a list of files to ensure that the files are arranged in a logical order that humans understand, rather than a simple dictionary order.

example:

Command: (acad_strlsort (list "file200.txt" "file100.txt" "file10.txt" "file5.txt"))
("file10.txt" "file100.txt" "file200.txt" "file5.txt")


Command: (vl-sort (list "file200.txt" "file100.txt" "file10.txt" "file5.txt") '(lambda(x y)(xdrx-string-logical< x y)))
("file5.txt" "file10.txt" "file100.txt" "file200.txt")

Code - Auto/Visual Lisp: [Select]
  1. (defun xd::string:sortlist (strl)
  2.   (vl-sort strl '(lambda (x y) (xdrx_string_logical< x y)))
  3. )
  4.  
  5. ;assoc string list sort
  6.  
  7. (defun xd::string:assocsortlist (strl)
  8.   (vl-sort strl '(lambda (x y) (xdrx_string_logical< (car x)(car y))))
  9. )


xd::string:assocsortlist
_$

(("file100.txt" (1 2 3)) ("file0.txt" (1 2 3)) ("file20.txt" (1 2 3)) ("file300.txt" (1 2 3)))
(("file0.txt" (1 2 3)) ("file20.txt" (1 2 3)) ("file100.txt" (1 2 3)) ("file300.txt" (1 2 3)))
_$
6
I have lsip that opens Microsoft Edge and then launches my default PDF reader using a function called. Here's the code
(If someone knows who should get credit for this I am more than willing to remark it
Code: [Select]
(defun launchpdf (pdfname / shell)
  (vl-load-com)
  (setq pdfname (vl-string-translate "|" "\\" pdfname))
  (setq shell
        (vla-getinterfaceobject
          (vlax-get-acad-object)
          "Shell.Application"
        )
  )
  (vlax-invoke-method shell 'Open pdfname)
  (vlax-release-object shell)
  (princ)
)

(defun c:cheats ()
  (launchpdf "https://teams.company/revit//revitblog/PublishingImages/New%20user%20Packet/cheatsheet.pdf")
)


However, I'm encountering an issue with hosting a PDF cheatsheet on our company server. Currently, I'm only able to access it via an HTTPS link. Is there a workaround to enable me to keep the cheatsheet on our company server? If I launch the pdf off my computer it works the way I want.

Code: [Select]
(defun c:cheats ()
  (launchpdf "\\\\dt-lshaw2\\dcapps\\help.pdf")
)

Unfortunately, IT has been unable to provide a non-HTTPS link. Any suggestions on how to resolve this would be appreciated."
7
CAD General / Re: Batch Find & Replace Text AutoCAD 2023
« Last post by Lee Mac on May 10, 2024, 12:46:23 PM »
Try setting LISPSYS to 0.
8
AutoLISP (Vanilla / Visual) / Re: 3d polyline splitting
« Last post by ribarm on May 10, 2024, 10:52:29 AM »
@mariolino0099
I've fixed (while) endless loop, but it doesn't follow exact math because segments lengths are less than 0.7 units, so if I divide it with 0.7 and (fix) that number I get 0 - which gives another error - divide by zero... So, I had to include one (if) statement that will ensure that your first *.DWG is processed correctly with verices numbers like you presented on right side 3d polyline, and your second *.DWG is processed with that second - else (if) statement (setq n (fix (1+ (/ dd d)))) ... That 1+ is to ensure that divide by zero doesn't occur...
So, test my codes now, as I think that better than this is not neccessary...
10
.NET / Re: Using the Generic KeyValuePair<>
« Last post by retsameht on May 10, 2024, 05:38:04 AM »
Just a heads up: Don't use the code in this file until I fix it:

https://github.com/ActivistInvestor/AcMgdUtility/blob/main/DocumentCollectionExtensions.cs

UPDATE 5/10/24: Bugs fixed (WaitForIdle(), and WaitUntil() were hanging AutoCAD :oops:).

WaitForIdle() is a solution to a problem that has irked me for a long time (handling the next Application.Idle event). I had previously dealt with it using a class that wraps the handler for the event, but that still required the code to be run in the Idle event handler to be passed in a delegate.

WaitForIdle() is a far-simpler and better solution that requires nothing but an awaited method call, followed by the code that should run after the Idle event is raised.

Code - C#: [Select]
  1. /// WaitForIdle():
  2.  
  3. public static async void MyMethod()
  4. {
  5.    var DocMgr = Application.DocumentManager;
  6.    
  7.    // wait for an Idle event to be raised:
  8.    
  9.    await DocMgr.WaitForIdle();
  10.    
  11.    // Code appearing here will not run until
  12.    // the next Idle event is raised and there
  13.    // is an active document.
  14.    
  15.    var doc = DocMgr.MdiActiveDocument;      
  16.    doc.Editor.WriteMessage("An Idle event was raised.");
  17. }
  18.  
  19.  
  20. /// WaitUntil():
  21.  
  22. public static async void MyMethod()
  23. {
  24.    var DocMgr = Application.DocumentManager;
  25.    
  26.    // Waits until there is an active document
  27.    // that is in a quiescent state:
  28.    
  29.    await DocMgr.WaitUntil(doc => doc.Editor.IsQuiescent);
  30.    
  31.    // Code appearing here will not run until
  32.    // the next Idle event is raised; there is
  33.    // an active document; and that document
  34.    // is in a quiescent state.
  35.    
  36.    var doc = DocMgr.MdiActiveDocument;      
  37.    doc.Editor.WriteMessage("The Drawing Editor is quiescent");
  38. }
  39.  
  40.  
Pages: [1] 2 3 ... 10