Jump to content

Recommended Posts

Posted
22 hours ago, Steven P said:

 

That's strange, in my testing it works as I expected. Are you able to post a sample drawing with an arc that rotates?

 

 

Going to look at the other object types sometime today for you. There is a list at the top of 'Flatten Lines' that work at the moment for info.

 

 

Thanks for interest. you can try this dwg also. I 'm waiting yours code.  

arc.dwg

Posted
17 hours ago, mhupp said:

 

Then something wasn't created or modified. aka trying to exploding a invalid or corrupted region, or one that is on a locked layer. maybe run audit and purge before and then check if entity is on a locked layers.

 

-Edit

Writing lisp isn't the hard part. figuring out all the different things that could go wrong and how to handle that is the hard part. had a user that would always select things with the crossing selection option(bottom right to top left) and complain about how my lisp was picking up things "outside" what they where selecting.

I'm sure I did because I tried exploding an object. But it didn't fill. There must be an error somewhere, but I couldn't find it, so I tried another method. Also, I'm a new programmer and I started writing lips without knowing anything about ACAD, so it was extra difficult. I'm glad this forum exists :)))

  • Like 1
Posted

arcs in this case will need to be converted to ellipses to display properly.. something to think about

  • Confused 1
Posted (edited)
7 hours ago, Steven P said:

arcs in this case will need to be converted to ellipses to display properly.. something to think about

As Steven P said, your arcs in order to keep the same display or look should be converted to ellipses or splines, because they are in 3d and to be displayed in 2d should be converted because they're not plain sections of circles as an arc in 2d is meant to be, that's why most of the codes don't apply to what you want

Edited by Isaac26a
Typos
  • Like 1
Posted (edited)

see if this drawing is correct. I used project

 

from pyrx import Ap, Ax, Db, Ed, Ge
from timeit import default_timer as timer

# register command 
@Ap.Command()
def doit():
    try:
        db = Db.curDb()
        
        # selection set
        ps, ss = Ed.Editor.select()
        if ps != Ed.PromptStatus.eOk:
            raise RuntimeError("Selection Error! {}: ".format(ps)) 
        
        start = timer()
        failedEnts = set()
        newents = []
        
        # createa plane to project on to
        plane = Ge.Plane(Ge.Point3d.kOrigin,Ge.Vector3d.kZAxis)
    
        for id in ss.objectIds(Db.Curve.desc()):
            dbc = Db.Curve(id)
            try:
                gec = dbc.getAcGeCurve()
                
                # project
                geproj = gec.project(plane,Ge.Vector3d.kZAxis)
                if not geproj.isKindOf(Ge.kCurve3d):
                    continue
                geprojCurve = Ge.Curve3d.cast(geproj)
                
                #convert to AcDbCurve
                dbproj = Db.Core.convertGelibCurveToAcDbCurve(geprojCurve)
                dbproj.setDatabaseDefaults()
                dbproj.setLayer(dbc.layer())
                newents.append(dbproj)
                
                #erase the old
                dbc.upgradeOpen()
                dbc.erase()
                # do linetypes 
            except:
                failedEnts.add(dbc.isA().name())
                
        #add the new flattened entities 
        db.addToModelspace(newents)
        end = timer()
        print(end - start)
        
    except Exception as err:
        print(err)

 

project.png.e52353b13647df48675c6ea932f0b0e9.png

 

 

Edited by Danielm103
updated code
Posted

Coming back to this one, I was thinking first off a simple task to write something faster - things like the arcs to ellipses slowing things down a bit.

 

Maybe a different approach, are you able to share the LISP you have now, the one that works, and we can look to see if we can make it work faster?

Posted
On 8/26/2025 at 4:33 PM, Steven P said:

Coming back to this one, I was thinking first off a simple task to write something faster - things like the arcs to ellipses slowing things down a bit.

 

Maybe a different approach, are you able to share the LISP you have now, the one that works, and we can look to see if we can make it work faster?

Unfortunately, I can’t share the LISP code itself, but I can explain the underlying logic.I use a helper function that processes each entity type. When it encounters a block, it gathers the block’s contents into a list; once the top-level selection is done, it feeds that list back into the same function to process all nested entities.”

Posted

Did you have a look at my drawing? Python converted those arcs to ellipses in milliseconds. If you can run python, then it would be pretty easy to make it callable from lisp 

Posted
35 minutes ago, Danielm103 said:

Did you have a look at my drawing? Python converted those arcs to ellipses in milliseconds. If you can run python, then it would be pretty easy to make it callable from lisp 

sorry ı dont know how to use this code in  acad. I'm trying

Posted
48 minutes ago, Danielm103 said:

Did you have a look at my drawing? Python converted those arcs to ellipses in milliseconds. If you can run python, then it would be pretty easy to make it callable from lisp 

That sounds to me that you are trying to pull us to the dark side, sounds pretty tempting, would you walk us through? 

  • Funny 1
Posted (edited)
37 minutes ago, Isaac26a said:

That sounds to me that you are trying to pull us to the dark side, sounds pretty tempting, would you walk us through? 

LOL! Only for items that look difficult, or painful in lisp, where there’s a possible built in function.  This drawing took 0.03673760 seconds to process.

 

if the drawing is indeed correct, have a look here for how to run python https://github.com/CEXT-Dan/PyRx

arc2.dwg

Edited by Danielm103
  • Like 1
  • 2 weeks later...
Posted (edited)

This thread was mentioned in a similar discussion, so sharing my reply here in kind. 

 

If you can compile .NET, use @Danielm103's code - if you instead use Visual LISP, this may help: 

 

  

3 minutes ago, BlackBox said:

This does: 

(defun c:FOO (/ *error* _move _set elev acDoc ss objName pt i)

  (defun *error* (msg)
    (if ss (vla-delete ss))
    (if acDoc (vla-endundomark acDoc))
    (cond ((not msg))                                                   ; Normal exit
          ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
          ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
    )
    (princ)
  )

  (defun _move (prop /)
    (vla-move
      x
      (vlax-3d-point '(0 0 0))
      (vlax-3d-point
        (mapcar
          '-
          (list (car (setq pt (vlax-get x prop))) (cadr pt) elev)
          pt
        )
      )
    )
  )

  (defun _set (prop /)
    (vlax-put
      x
      prop
      (list (car (setq pt (vlax-get x prop)))
            (cadr pt)
            elev
      )
    )
  )

  (if
    (and
      (ssget
        "_:L"
        '(
          (0
            .
            "ARC,ATTDEF,CIRCLE,DIMENSION,ELLIPSE,HATCH,INSERT,*LEADER,LINE,*POLYLINE,MTEXT,POINT,REGION,SOLID,SPLINE,TEXT"
          )
         )
      )
      ;; someone asked if they could pick a point:
      ;;(setq elev (getpoint "\nSpecify point for elevation: "))
      ;;(setq elev (last elev))
      (setq elev (getreal "\nEnter an elevation: "))
    )
    (progn
      (vla-startundomark
        (setq acDoc (vla-get-activedocument (vlax-get-acad-object)))
      )
      (vlax-for x (setq ss (vla-get-activeselectionset acDoc))
        (setq pt nil)
        (cond
          ((vl-position
             (setq objName (vla-get-objectname x))
             '("AcDbArc" "AcDbCircle" "AcDbEllipse")
           )
           (_set "center")
          )
          ((vl-position objName '("AcDbAttributeDefinition" "AcDbMText" "AcDbText"))
           (_set "insertionpoint")
          )
          ((wcmatch objName "AcDb*Dimension")
           (_move "textposition")
          )
          ((= "AcDbBlockReference" objName)
           ;; <-- test for and ignore xrefs here, if needed
           (_set "insertionpoint")
          )
          ((= "AcDbLine" objName)
           (_set "startpoint")
           (_set "endpoint")
          )
          ((= "AcDbPoint" objName)
           (_set "coordinates")
          )
          ((vl-position objName '("AcDbHatch" "AcDbPolyline" "AcDb2dPolyline"))
           (vla-put-elevation x elev)
          )
          ((vl-position objName '("AcDb3dPolyline" "AcDbLeader" "AcDbSolid"))
           (setq pt (vlax-get x 'coordinates))
           (setq i 0)
           (setq pt
                  (mapcar
                    (function
                      (lambda (n)
                        (setq i (1+ i))
                        (if (= 0 (rem i 3))
                          elev
                          n
                        )
                      )
                    )
                    pt
                  )
           )
           (vlax-put x 'coordinates pt)
          )
          ((= "AcDbMLeader" objName)
            (setq pt (vlax-invoke x 'GetLeaderLineVertices 0))
            (vla-move
              x
              (vlax-3d-point
                (setq pt (list (car pt) (cadr pt) (caddr pt)))
              )
              (vlax-3d-point (list (car pt) (cadr pt) elev))
            )
          )
          ((= "AcDbRegion" objName)
            (setq pt (vlax-get (car (setq i (vlax-invoke x 'explode)))
                               'startpoint
                     )
            )
            (vla-move
              x
              (vlax-3d-point
                (setq pt (list (car pt) (cadr pt) (nth 2 pt)))
              )
              (vlax-3d-point (list (car pt) (cadr pt) elev))
            )
            (foreach line i (vla-delete line))
          )
          ((= "AcDbSpline" objName)
           (if (= :vlax-true (vla-get-isplanar x))
             (progn
               (setq pt (vlax-get x 'controlpoints))
               (vla-move
                 x
                 (vlax-3d-point
                   (setq pt (list (car pt) (cadr pt) (nth 2 pt)))
                 )
                 (vlax-3d-point (list (car pt) (cadr pt) elev))
               )
             )
             (progn
               (setq x (entget (vlax-vla-object->ename x)))
               (setq x
                      (mapcar
                        (function
                          (lambda (p)
                            (cond
                              ((and (member (car p) '(10 11 12 13))
                                    (listp (cdr p))
                                    (= 3 (length (cdr p)))
                               )
                               (list (car p)
                                     (cadr p)
                                     (caddr p)
                                     elev
                               )
                              )
                              (t p)
                            )
                          )
                        )
                        x
                      )
               )
               (entmod x)
             )
           )
          )
          (T nil)
        )
      )
    )
  )

  (*error* nil)
)

 

 

Edited by BlackBox
  • Like 1
Posted
13 minutes ago, Danielm103 said:

FYI, it’s not .NET, it’s Python, so no compiling required :)

https://github.com/CEXT-Dan/PyRx

 

Though .NET certainly would work, the function is AcGeCurve3d::project

Maybe similar to  PROJECTGEOMETRY

 

It was more of a qualifier... While I'm sure they exist, I've never personally met anyone who used Python and couldn't compile .NET Haha

  • Like 1

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...