Author Topic: Issue selecting certain multileader objects  (Read 635 times)

0 Members and 1 Guest are viewing this topic.

slissner

  • Mosquito
  • Posts: 4
Issue selecting certain multileader objects
« on: March 25, 2024, 09:31:49 PM »
I am working on an AutoLISP command which involves rotating Multlleader objects (attached). I am having an issue where certain Multileader objects are crashing with the error:
 
Exception has occurred. AutoCAD.Application: Invalid index
 
Some objects crash my routine and others don’t, I have been unable to figure out why. I have attached the AutoLISP script. I am crashing on line 58 when I try and retrieve an attribute from the Multileader with the line:
 
Code: [Select]
(vlax-invoke ml_obj "GetDoglegDirection" 0)
           
I’d appreciate any pointers or documentation to help get me moving in the right direction, for now I am quite stumped.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Issue selecting certain multileader objects
« Reply #1 on: March 26, 2024, 08:20:55 AM »
Some objects crash my routine and others don’t
post a dwg with such an object

slissner

  • Mosquito
  • Posts: 4
Re: Issue selecting certain multileader objects
« Reply #2 on: March 26, 2024, 01:01:38 PM »
post a dwg with such an object

Here you go. The red, 15 degree multileader crashes the command.

ronjonp

  • Needs a day job
  • Posts: 7529
Re: Issue selecting certain multileader objects
« Reply #3 on: March 26, 2024, 01:52:56 PM »
This could be part of the problem.
Quote
Auditing AcDsRecords
Total errors found 68 fixed 68
Erased 68 objects
See if the attached file works.


Windows 11 x64 - AutoCAD /C3D 2023

Custom Build PC

slissner

  • Mosquito
  • Posts: 4
Re: Issue selecting certain multileader objects
« Reply #4 on: March 26, 2024, 04:00:39 PM »
No luck unfortunately. I've tried auditing other files that engineers have brought me and had no success with those either. Maybe it has something to do with the way that the objects are created? I'm at a loss.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Issue selecting certain multileader objects
« Reply #5 on: March 27, 2024, 09:30:43 AM »
post a dwg with such an object

Here you go. The red, 15 degree multileader crashes the command.
(setq dogLegDir (vlax-invoke ml_obj "GetDoglegDirection" (vlax-invoke ml_obj "GetLeaderIndex" 0)))

slissner

  • Mosquito
  • Posts: 4
Re: Issue selecting certain multileader objects
« Reply #6 on: March 27, 2024, 12:48:23 PM »
This fix seems to be working! Thank you VovKa!

dexus

  • Bull Frog
  • Posts: 208
Re: Issue selecting certain multileader objects
« Reply #7 on: March 27, 2024, 01:25:26 PM »
You can also have a look at this: https://www.theswamp.org/index.php?topic=55023.msg614986#msg614986
It is able to retreive multiple arrows on a single mleader.

VovKa

  • Water Moccasin
  • Posts: 1632
  • Ukraine
Re: Issue selecting certain multileader objects
« Reply #8 on: March 27, 2024, 01:53:01 PM »
This fix seems to be working! Thank you VovKa!
welcome to theswamp, slissner

Lee Mac

  • Seagull
  • Posts: 12915
  • London, England
Re: Issue selecting certain multileader objects
« Reply #9 on: April 05, 2024, 06:31:36 AM »
I think this might be cleaner -
Code - Auto/Visual Lisp: [Select]
  1. (defun doglegdirection ( ent / enx )
  2.     (if (and (setq enx (entget ent))
  3.              (= "MULTILEADER" (cdr (assoc 0 enx)))
  4.              (setq enx (member '(302 . "LEADER{") enx))
  5.         )
  6.         (cdr (assoc 11 enx))
  7.     )
  8. )
Code - Auto/Visual Lisp: [Select]
  1. (defun c:test ( / ent )
  2.     (if (setq ent (car (entsel)))
  3.         (print (doglegdirection ent))
  4.     )
  5.     (princ)
  6. )

dexus

  • Bull Frog
  • Posts: 208
Re: Issue selecting certain multileader objects
« Reply #10 on: April 05, 2024, 08:57:45 AM »
As always making it look simple, well done.

I modified it so you can check for multiple leaders, in case the mleader has an arrow on both sides:
Code - Auto/Visual Lisp: [Select]
  1. (defun doglegdirection ( ent / enx rtn )
  2.   (if
  3.     (and
  4.       (setq enx (entget ent))
  5.       (= "MULTILEADER" (cdr (assoc 0 enx)))
  6.       (while (setq enx (member '(302 . "LEADER{") enx))
  7.         (setq rtn (cons (cdr (assoc 11 enx)) rtn)
  8.               enx (cdr enx))
  9.       )
  10.     )
  11.     (reverse rtn)
  12.   )
  13. )