How to change ARC, SPLINE & POLYLINE to CIRCLE?

How to change ARC, SPLINE & POLYLINE to CIRCLE?

sarsivi30993
Advocate Advocate
1,718 Views
4 Replies
Message 1 of 5

How to change ARC, SPLINE & POLYLINE to CIRCLE?

sarsivi30993
Advocate
Advocate

Dear All,

 

I have some issues in pdf 2 cad conversion using AutoCAD software. Conversion successfully all objects is coming. But, circle objects only different properties (Ex. polyline, Arc, Line, Spline) coming not circle object.

 

I have attached that pdf 2 cad drawing for your reference.

 

Any shortcuts and lisp please tell and useful for me.

 

Thanks in advance.

0 Likes
1,719 Views
4 Replies
Replies (4)
Message 2 of 5

ronjonp
Mentor
Mentor

Have you used the code HERE? most of the time for these ugly translations you're going to need to figure out some form of common features to be able to isolate the areas needed for cleanup. All I did was add 'SPLINE,ELLIPSE' to the filter and changed the fuzz value to 1e-1 to isolate most of your 'circles'. Sure it's not perfect but faster that doing it manually 8-).

image.png

 

 

0 Likes
Message 3 of 5

Kent1Cooper
Consultant
Consultant

[It's generally not a good idea to post the same question in more than one place.  If a solution is found in one place, someone who wants to do the same thing may find the other  place in a Search, and not know that there's a solution.]

 

I think this is the more appropriate Forum, since something like a routine to make that kind of replacement would be a customization.  I have routines to convert Arcs to full Circles, or regular Polyline polygons to Circles, but the "circles" in your drawing are too varied in their components for anything I know of to handle reliably.

 

But I agree with @Anonymous over in the other thread that you would be much better off getting the .DWG files instead of converting .PDF files.

Kent Cooper, AIA
0 Likes
Message 4 of 5

Anonymous
Not applicable

I can think of a way, but it might get quite complicated for anything other than arcs, arcs would be simple. 

     A circle can be defined by 3 points on its perimeter. Therefore if you have 3 points of each polyline and spline, you can form the equation that defines the circle those three points would lie on. Then you can grab a 4th point, if its distance is within some tolerance to the equation of the circle formed by the first 3, you most likely have a circular spline or polyline. You can test with more points to be safe. Once you know that its a circle and its equation, just replace the entity with the circle entity described by the equation. 

   Where it gets complicated is that your splines are defined by control points and not fit points. Fit points would make this task easy, control points is another story. AutoCAD splines are B-splines, I have writen a python code that converts splines to polylines, which you can use to determine points along your splines and pass it through the algorithm I described above. This is using a python package called pyautocad, I think its way easier than lisp or VBA. In any case you can use the same logic and transcribe the code to another language. Hope this helps.

def my_B_spline(obj,resolution):
    knots=obj.knots
    points=obj.controlpoints
    degree=obj.degree
    mtx,numP=form_matrix(points)
    def N(i,p,u):
        if p==0:
            if knots[i]<=u<knots[i+1]:
                return 1
            else:
                return 0
        else:
            if not (knots[i+p]-knots[i])==0:
                eq1=(u-knots[i])/(knots[i+p]-knots[i])
            else:
                eq1=0
            if not (knots[i+p+1]-knots[i+1])==0:
                eq2=(knots[i+p+1]-u)/(knots[i+p+1]-knots[i+1])
            else:
                eq2=0
            
            return eq1*N(i,p-1,u)+eq2*N(i+1,p-1,u)
    output=mtx[0]
    for u in np.linspace(knots[0],knots[-1],num=resolution,endpoint=False)[1:]:
        nextPoint=np.array([0,0,0],dtype='float')
        for i in range(0,numP):
            nextPoint+=N(i,degree,u)*mtx[i]
        output=np.vstack([output,nextPoint])
    return np.vstack([output,mtx[-1]])
Message 5 of 5

sarsivi30993
Advocate
Advocate

AutoCAD reply to *error* no function.

0 Likes