Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Is there a way to change linework within multiple blocks from a 3d polyline to a 2d polyline simultaneously?

jmottet
Participant

Is there a way to change linework within multiple blocks from a 3d polyline to a 2d polyline simultaneously?

jmottet
Participant
Participant

First post here, and I'm needing some help.   

 

I'm running a secondary program within C3D that requires blocks in order to function.  These blocks are actually outlines of framing panels, so they're rectangles of different widths and lengths.  In order for the program to run, each block must have 2 requirements.

 

1.  The elements within the block must be a closed polyline with only vertices at the 4 corners

2.  The closed polyline must be a 2D polyline

 

I use another program to export the .dxf/.dwg drawing in order to get my blocks, but when I open the blocks they are made up of 3D polylines and not 2D polylines.  I'm aware of the "convert 3D polylines to 2D polylines" function, but that would require me to open up each block individually and edit that way.  Some of these files have a few thousand blocks so manually editing them isn't feasable.

 

So, my question...Is there a way to change the linework within multiple blocks from a 3D polyline to a 2D polyline without having to open up each block indivually?  Hopefully my questions makes sense.  Thanks.

 

 

 

0 Me gusta
Responder
Soluciones aceptadas (2)
1.374 Vistas
24 Respuestas
Respuestas (24)

ChrisRS
Mentor
Mentor

Sorry, I do not know of a way to do this. Maybe with a lisp routine that stepped through a collection of blocks. 

 

Blocks are a core AutoCAD feature. You might have better luck in the AutoCAD forum.

 

Christopher Stevens
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Me gusta

Pointdump
Mentor
Mentor

Hi John,
Welcome to the Autodesk Forums.
What is the "secondary program" and what is the "another program"? My first thought is to change the 3D to 2D before the block is created. Are there thousands of unique blocks, or just one? If one, then use the Block Editor.
Dave

Dave Stoll
Las Vegas, Nevada

EESignature

64GB DDR4 2400MHz ECC SoDIMM / 1TB SSD
NVIDIA Quadro P5000 16GB
Windows 10 Pro 64 / Civil 3D 2024
0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

upload a dwg-file so we can see what you really have.

Also a question about "2D-Polyline" ... just to make sure, really "2D-Polyline" or the more common version of two dimensional polyline which is named "LW-Polyline" internal in AutoCAD?

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

jmottet
Participant
Participant

Dave,

 

Without getting into too much detail, the secondary program is a custom .dll program used for wood framing.  This loaded program uses blocks created from a section view slice of a building modeled in SketchUp (the other program/software).  The input is a .dxf exported from SU, and the output is a different .dxf created within C3D after the program works its magic.

 

The issue is SketchUp can export each wall panel as its own block (ok, perfect there), but the elements within said blocks are 3D polylines, they need to be 2D polylines. 

 

There are several thousand blocks in some drawings, so using the block editor isn't feasible.

 

I've attached an example .dxf so you can see what I'm referring to.  There are only 2 blocks in there, but if you open the block editor on each one, they are made up of a 3D polyline when looking at the properties.  They need to be a regular polyline in order for my program to work. Just image there are 1500 of these blocks in the same file.  I need a way to dig into them all at once and change the 3D polylines into regular 2D polylines.

 

I'd also like to point out that the program works just fine, because some inputs I get from customers already have the blocks already made up of 2D polylines.  Those customers use a special panel design software that exports the files how I need them.  Those files are great.  I open them up, run the .dll program and get my output file.  Easy peasy.

 

If the files aren't how I need them, ie. they've been designed in a program that doesn't export the blocks correctly, I have to re-trace every wall in the program that exports correctly.   So, I'm looking for a way to avoid tracing over SU outputs in order to get the output the program can read.  

 

A lot of customers have Software #1 that outputs wall panels correctly how I need them.  Others use Software #2 that gives THEM the output they need, but not me. I've got to own Software #1, which is not cheap, to trace over their work from Software #2.  I want to eliminate the re-work and the need to own Software #1.  

0 Me gusta

jmottet
Participant
Participant

Alfred,

 

I only use c3d, so I'm not sure about the lw-polyline.  All I know is it's a polyline created when I use the "PL" command and it shows up as just "polyline" in my properties.   Thanks

0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> All I know is it's a polyline created when I use

>> the "PL" command 

That's why I was asking ...

 

If the attached dwg-file matches your needs you can use this VBA macro inside Civil 3D.

VBA-Enabler might not be installed, if not you can download and install it from here:

https://knowledge.autodesk.com/support/autocad/downloads/caas/downloads/content/download-the-microso...

 

This is the code:

Public Sub test()
    Dim tBl As AcadBlock
    For Each tBl In ThisDrawing.Blocks
        If doConvert(tBl) Then
            Call conv(tBl)
        End If
    Next
End Sub

Private Function doConvert(ByRef BlDef As AcadBlock) As Boolean
    Dim tRetVal As Boolean
    tRetVal = True
    If BlDef.IsLayout Then tRetVal = False
    If BlDef.IsXRef Then tRetVal = False
    doConvert = tRetVal
End Function

Private Function conv(ByRef BlDef As AcadBlock) As Boolean
    Dim tRetVal As Boolean: tRetVal = True
    Dim tEnt As AcadEntity
    Dim t3DPoly As Acad3DPolyline
    Dim tCoords As Variant
    Dim tCoords2() As Double
    Dim t2DPoly As AcadLWPolyline
    Dim i As Integer
    Dim i2 As Integer
    
    For Each tEnt In BlDef
        If TypeOf tEnt Is Acad3DPolyline Then
            Set t3DPoly = tEnt
            tCoords = t3DPoly.Coordinates
            ReDim tCoords2((UBound(tCoords) + 1) / 3 * 2 - 1)
            For i = LBound(tCoords) To UBound(tCoords) Step 3
               i2 = i / 3 * 2
               tCoords2(i2) = tCoords(i)
               tCoords2(i2 + 1) = tCoords(i + 1)
            Next
            Set t2DPoly = BlDef.AddLightWeightPolyline(tCoords2)
            t2DPoly.Layer = t3DPoly.Layer
            t2DPoly.color = t3DPoly.color
            t3DPoly.Delete
        End If
    Next
    
    conv = tRetVal
End Function

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

jmottet
Participant
Participant

Alfred,

 

I think we're getting closer.  My program didn't work, but I THINK I know why.  Wondering if the code could be modified to address this?

 

1.  When I open the block, it now says "polyline" instead of 3D polyline which is a success!  However, it isn't a closed polyline.  I closed it and ran my program, but the program still doesn't work.

 

I know absolutely zero about code, but I'm guessing the reason it didn't work after I closed is because in the code, I saw that it says LW-Polyline.  I'm assuming the LW-Polyline and Polyline both display as "polyline" in the properties in C3D but they're actually a little bit different?  So is there a way to close it the script?  and is there a way to make it a polyline and not a light weight polyline?

 

Appreciate all of your help on this.

0 Me gusta

Neilw_05
Mentor
Mentor

This is a shot in the dark. Microstation DGN format supports both 3D and 2D files. If you export your blocks to a 2D DGN file it should convert all 3D objects to 2D. From there you convert the DGN back into DWG format. The blocks should then consist of 2D geometry. I don't know enough about the translation process to say what the issues might be. This is just an idea to investigate.

Neil Wilson (a.k.a. neilw)
AEC Collection/C3D 2024, LDT 2004, Power Civil v8i SS1
WIN 10 64 PRO

http://www.sec-landmgt.com

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> I'm assuming the LW-Polyline and Polyline both display as "polyline" in the properties

No, however LW-Polyline is the default after installation of Civil 3D, if PLINETYPE is modified, then a different object will be created and shown as "2D-Polyline" in the property window.

 

I have attached a file with 2D-Polyline instead of (LW-)Polyline and they are closed.

 

This is the modified code:

Public Sub test()
    Dim tBl As AcadBlock
    For Each tBl In ThisDrawing.Blocks
        If doConvert(tBl) Then
            Call conv(tBl)
        End If
    Next
End Sub

Private Function doConvert(ByRef BlDef As AcadBlock) As Boolean
    Dim tRetVal As Boolean
    tRetVal = True
    If BlDef.IsLayout Then tRetVal = False
    If BlDef.IsXRef Then tRetVal = False
    doConvert = tRetVal
End Function

Private Function conv(ByRef BlDef As AcadBlock) As Boolean
    Dim tRetVal As Boolean: tRetVal = True
    Dim tEnt As AcadEntity
    Dim t3DPoly As Acad3DPolyline
    Dim tCoords As Variant
    Dim tCoords2() As Double
    'Dim t2DPoly As AcadLWPolyline
    Dim t2DPoly As AcadPolyline
    Dim i As Integer
    Dim i2 As Integer
    
    For Each tEnt In BlDef
        If TypeOf tEnt Is Acad3DPolyline Then
            Set t3DPoly = tEnt
            tCoords = t3DPoly.Coordinates
'            ReDim tCoords2((UBound(tCoords) + 1) / 3 * 2 - 1)
'            For i = LBound(tCoords) To UBound(tCoords) Step 3
'               i2 = i / 3 * 2
'               tCoords2(i2) = tCoords(i)
'               tCoords2(i2 + 1) = tCoords(i + 1)
'            Next
'            Set t2DPoly = BlDef.AddLightWeightPolyline(tCoords2)
            Set t2DPoly = BlDef.AddPolyline(tCoords)
            t2DPoly.Closed = True
            t2DPoly.Layer = t3DPoly.Layer
            t2DPoly.color = t3DPoly.color
            t3DPoly.Delete
        End If
    Next
    
    conv = tRetVal
End Function

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

jmottet
Participant
Participant

Ok. Unfortunately this didn't work.  

 

I was thinking about another way to approach this to see if it would work.  Here would be the steps.

 

1.  Open up my drawing as normal.  This drawing would have all of the blocks, but the linework within the block would still be a 3D closed polyline.

 

2.  Explode all the blocks.

 

3.  Use the standard "convert 3D polylines to 2D polylines" function

 

4.  Run some sort of script to convert all of the closed polylines into their own individual block.  This is obviously the sticking point for me.

0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> this didn't work

What does not work, it converts the 3D-Polylines inside your blocks to closed 2D-Polylines.

What does now fail?

 

>> some sort of script to convert all of the closed polylines

>> into their own individual block

At the moment you explode blocks you loose the block properties like layer, color, insertion point, rotation...

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

jmottet
Participant
Participant

My secondary program doesn't work after the conversion.  When I open the block after running the script, the upper right hand corner of the rectangle isn't shown as a vertex.  It's shown as a midpoint.  

 

Capture.JPG

0 Me gusta

Alfred.NESWADBA
Consultant
Consultant

Hi,

 

>> the upper right hand corner of the rectangle isn't shown as a vertex

It uses the same vertices the 3D-Polyline had ... and I have not seen any description about start point or vertex order or anything else has to change.

 

Please let me know ALL needs and I'll try to add this to my macro, it's hard to do a one correction now and another one then, and ...

 

- alfred -

------------------------------------------------------------------------------------
Alfred NESWADBA
ISH-Solutions GmbH / Ingenieur Studio HOLLAUS
www.ish-solutions.at ... blog.ish-solutions.at ... LinkedIn ... CDay 2025
------------------------------------------------------------------------------------

(not an Autodesk consultant)
0 Me gusta

Neilw_05
Mentor
Mentor

FYI, I ran a test using the DGN approach. It does convert the 3D polys to 2D polys. It doesn't close the polys though. Maybe this would simplify the script by eliminating the conversion process.

Neil Wilson (a.k.a. neilw)
AEC Collection/C3D 2024, LDT 2004, Power Civil v8i SS1
WIN 10 64 PRO

http://www.sec-landmgt.com

Joe-Bouza
Mentor
Mentor

FLATTEN

 

drills into blocks

Joe Bouza
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Me gusta

Neilw_05
Mentor
Mentor

Does flatten convert 3D polys to 2D?

Neil Wilson (a.k.a. neilw)
AEC Collection/C3D 2024, LDT 2004, Power Civil v8i SS1
WIN 10 64 PRO

http://www.sec-landmgt.com
0 Me gusta

Joe-Bouza
Mentor
Mentor

No, but if all the the vertices are the same elevation "0" isn't that the definition of 2d? Are  we sure flat isn't good enough

Joe Bouza
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Me gusta

Joe-Bouza
Mentor
Mentor

2d poly lines or poly lines without elevation?

Joe Bouza
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Me gusta

jmottet
Participant
Participant

I've attached an example file of what the block attributes must be in order for my processor to work.  This file was created in MiTek and is the format the processor reads.  This is a project on the larger size, so you can see how doing any individual block edits would be a PITA.  Doing some investigation and talking to the owners of the processor, this is what I've found to be requirements.

 

1.  Be a closed polyline.  Can't be a 3D closed polyline.  Based on the first code, it can't be LW polylines either.  All I know is it says "polyline" in the properties on these blocks that work.  If you look at the attached file, there are some exterior walls that show sheathing.  The processor ignores these, because it only picks up the closed polylines within the block, and the sheathing isn't shown as a closed polyline.

2.  There needs be vertices only at the corner points of the rectangle.

3.  There can only be 4 vertices with the closed polyline.  No intermediate vertices.

 

The attached file meets all of the above requirements, so in theory, if the block in the file I posted a few days ago can match the properties of this one, then it should work..In theory of course.

0 Me gusta