using macros to automatically adjust the DXF exports from SolidWorks for lasercutting

Hi everybody, this is my first post in this forum and my entire knowledge of CorelDraw is using it for laser cutting. So my apologies in advance if I'm making any mistakes (e.g. asking the question in the wrong forum etc)

We have a laser cutting machine in our lab which uses coreldraw to export the drawings to laser cutting software  as virtual printer. We also use solidworks to draw the sketches and export as DXF. when opening the DXF files in CorelDraw one has to do a lot of adjustments which is irritating and time consuming. I want to write a macro which automates these steps. consider this drawing for example:

the steps to adjust this drawing are:

  1. opening the dxf file
  2. removing the centerlines for the circle
  3. changing all the line widths to hairline
  4. changing the color to red
  5. grouping all the objects into one
  6. changing the page size in a way to be 0.5 mm bigger on each side. so given the object size adding 1mm to it on x and y
  7. centering the object to the page (ctrl+p)
  8. and saving

I was wondering if any of you could help me to know how I can write this macro.

Thanks in advance

P.S. here you may find an example of the dxf file.

Parents
No Data
Reply
  • There are of course different ways of approaching this. Here's one way:

    Sub work_on_DXF()
    Const dbl_margin_mm As Double = 0.5
    Dim s As Shape
    Dim unitDoc As cdrUnit
    
    unitDoc = ActiveDocument.Unit
    
    'delete all shapes with 0.18 mm line width
    ActivePage.Shapes.FindShapes(Query:="@outline.width = {0.18 mm}").Delete
    
    Set s = ActivePage.Shapes.All.Group
    
    s.Outline.Width = ConvertUnits(0.003, cdrInch, unitDoc)
    s.Outline.Color.RGBAssign 255, 0, 0
    
    ActivePage.SetSize s.SizeWidth + 2 * ConvertUnits(dbl_margin_mm, cdrMillimeter, unitDoc), s.SizeHeight + 2 * ConvertUnits(dbl_margin_mm, cdrMillimeter, unitDoc)
    
    s.CenterX = ActivePage.CenterX
    s.CenterY = ActivePage.CenterY
    
    ActiveDocument.Save
    
    End Sub
    
Children