Giter Site home page Giter Site logo

writer's Introduction

writer Verified on Openbase

A Javascript dxf generator, written in Typescript.

ci publish codecov

GitHub npm (scoped) npm

Installation

yarn add @tarikjabiri/dxf
# Or npm
npm i @tarikjabiri/dxf
# Or pnpm
pnpm add @tarikjabiri/dxf

Getting started

import { Writer, point } from "@tarikjabiri/dxf";

const writer = new Writer();
const modelSpace = writer.document.modelSpace;

// Add entites to the model space
modelSpace.addLine({
  start: point(),
  end: point(100, 100),
  // Other options...
});

// To get the dxf content just call the stringify() method
const content = writer.stringify();

More informations

Sponsors

Archilogic | Interior space for the digital world Slate Slate Mikey

writer's People

Contributors

deepankargupta13 avatar dependabot[bot] avatar fishorbear avatar fossabot avatar jean9696 avatar mmiscool avatar sunsetrain avatar tarikjabiri avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

writer's Issues

2.89 AddPolyline Undefined

I'm looking to add 3d polylines to my dxf, following the example in examples/polyline.ts, but it's throwing an undefined error.

Is this feature not yet implemented in release? Is there a way to use polyline right now?

support xdata

For example, the extended data of the font style

1001
ACAD
1000
YouYuan
1071
34353

i have issue when addImage

i add many image to cad but when i save to dwg or restart my computer file cad receive only last image. If I open the dxf file immediately it still receive all image
imgRegion.forEach((img, index) => {
let ordinateBotLeft = convertWgs84ToVn2000([
img.pointCenter[0] - dx / 2,
img.pointCenter[1] - dy / 2,
0,
]);
let ordinateTopRight = convertWgs84ToVn2000([
img.pointCenter[0] + dx / 2,
img.pointCenter[1] + dy / 2,
0,
]);
dxf.addImage(
"..\" + img.name + ".png",
img.name,
point3d(ordinateBotLeft[1], ordinateBotLeft[0]),
sizeMap[0],
sizeMap[1],
Math.abs(ordinateBotLeft[1] - ordinateTopRight[1]),
0
);
});

Singleton approach

Hi,

For now almost every objects are singletons, why do we need this ? Can we add a way to destroy the instance ? Or maybe just make DxfWriter scoped ?

Fill Rectangle Entity

Hello

I am having an issue filling up entity (Rectangle entity )
how can I implement that considering that I am having an canvas and then I transfer it into .dxf so it can be downloaded

the downloaded file is full of pixels when zooming in (of course because the rectangles are not filled )

can you help me doing that? ASAP

Thank you in advance

Leader line.

Hi sir,
I wanted to use leader line but its not there.
It will of great help if it can be added.

Thanks.

Dxf Image dimensions issue

Hi,

I am trying to add images to dxf with different dimensions, setting different width and height.
I found out that if I set smaller values to width and height, the images get bigger.

code example:

const dxf = new DxfWriter();

//IMAGE 1
const img1 = dxf.addImage(
'C:\Users\dev\Desktop\example.jpg', //Or the absolute path if not in the same folder.
'TEST', //The name of the image.
point3d(10, 10, 0), // The insertion point.
600, // The width of the image in pixels.
600, //The height of the image in pixels.
1, //The scale to be applied to the image.
0 //The rotation angle (Degrees) to be applied to the image.
);
img1.clippingStateFlag = 0;

//IMAGE 2
const img2 = dxf.addImage(
'C:\Users\dev\Desktop\example.jpg', //Or the absolute path if not in the same folder.
'TEST', //The name of the image.
point3d(-10, -10, 0), // The insertion point.
60, // The width of the image in pixels.
60, //The height of the image in pixels.
1, //The scale to be applied to the image.
0 //The rotation angle (Degrees) to be applied to the image.
);
img2.clippingStateFlag = 0;

const dxfString = dxf.stringify();
this.downloadFile(dxfString);


In the output dxf file, "IMAGE 2" (width 60 , height 60) is TEN times bigger than "IMAGE 1" (width 600 , height 600) and
I was expecting the opposite result.

image

Maybe am I missing something?

Header setvariable function

initially I was trying to set units to meter by
dxf.header.setVariable('$INSUNITS', 6); // units to meter
but the above code was not working

the below one worked but can we simplify this to the above one. the above one looks better and simple I think.
dxf.header.setVariable('$INSUNITS', { 70: 6 }); // units to meter

addLinearDim is not working precisely (e.g. from Jsketcher)

Hi,
Not sure if here is the right place, but when drawing in Jsketcher horizontal dimenstion, the dxf value is not precisely.
In the image below you can see it as "8000".
image

but the data after using the dxf export is calculate not as horizontal line but as free line with angle.
image

The dxf file:
image

And the the wrong calculated of Dimesion with "8066"
image
Thanks

Support for Polyface Meshes

Hi, fantastic library,

I was wondering if the library currently has support for creating polyface meshes?
It should be a variation of the polyline entity, however the section about polyline seems to be empty in the documentation: https://dxf.vercel.app/guide/entities.html#polyline

I found the flag for PolyfaceMesh available and I tried to create it like this:

    writer.addPolyline3D(vertices, {
      flags: PolylineFlags.PolyfaceMesh,
      layerName,
    });

However, I think I would need to be able to set flags on each vertex, to define faces for example? Am I missing something or is this just not supported yet? If so, do you have any plans to add support for this?

Best regards

Invalid block name do not throw or not re-formated

I found out that blocks with a name containing special characters like : are not supported by some viewer like Archicad. I think it could be nice to reformat it or to throw an error to avoid error.

question about updating existing dxf

hi, i am working on an application which can automatically add text to existing dxf drawings.

I notice your application "dxf" can create new dxf file, would it be possible if you read existing dxf files first and then I put some new TEXTs to the dxf file, later export as a new dxf ?

Spline with weights

Hello,

Thank you for all the work done so far.

Currently splines with weights are not managed. It's a pity because we can't draw all the cases. Do you plan to implement this feature?

Thanks.

Multiple DIMSTYLE issues

When I add any number of DimStyles, the generated DXF document won't open on AutoCAD.

Inspecting the file I've found that there is an AcDbDimStyleTable subclass before each DIMSTYLE and this is causing the error.

As a workaround I changed the DxfDimStyle and DxfTable classes.

The DxfDimStyle class I commented this line:

dx.subclassMarker('AcDbDimStyleTable');

And on the DxfTable:

class DxfTable {
    constructor(name) {
        this.name = name;
        this.maxNumberEntries = 0;
        this.ownerObjectHandle = '0';
        this.handle = Handle.next();
        this.records = [];
    }
    dxify(dx) {
        dx.type('TABLE');
        dx.name(this.name);
        dx.handle(this.handle);
        dx.push(330, this.ownerObjectHandle);
        dx.subclassMarker('AcDbSymbolTable');
        dx.push(70, this.records.length);
        // Added this IF clause to ensure only one AcDbDimStyleTable
        if (this.name == "DIMSTYLE") {
            dx.subclassMarker('AcDbDimStyleTable');
        }
        for (const record of this.records)
            record.dxify(dx);
        dx.type('ENDTAB');
    }
}

This change allowed me to open the files on AutoCAD

not able to justify the text to middle center

when I am doing this
function drawText() {
const text = dxf.addText(point3d(20, 20, 0), 1, 'GGWP', {
rotation: 30,
horizontalAlignment: 1,
verticalAlignment: 2,
})
console.log('text: ', text);
}
the position of the text becomes origin
image
I tried second alignment point also
text.secondAlignmentPoint = point3d(20, 20, 0);
it is also not working
pls help

I am not able to add image in dxf

i tried this

const imgDef = dxf.addImage("door.jpg", 'door.jpg', point3d(20, 20, 0), 10, 10, 1, 0);

the file gets download without any error but the file is not opening it says press enter to continue and after that nothing happens.

i consoled the imgDef i got this
image

pls help.

Solid Hatching is not working

hi sir,
Solid hatching is not working, I tried the below code
const polyline = new HatchPolylineBoundary();
polyline.add(vertex(0, 0));
polyline.add(vertex(0, 10));
polyline.add(vertex(10, 10));
polyline.add(vertex(10, 0));

const polyline1 = new HatchPolylineBoundary();
polyline1.add(vertex(1, 1));
polyline1.add(vertex(1, 9));
polyline1.add(vertex(9, 9));
polyline1.add(vertex(9, 1));


// const edges = new HatchEdgesTypeData();
// edges.addLineEdgeData(point2d(0, 0), point2d(0, 10000));
// edges.addLineEdgeData(point2d(0, 10000), point2d(10000, 10000));
// edges.addLineEdgeData(point2d(10000, 10000), point2d(10000, 0));
// edges.addLineEdgeData(point2d(10000, 0), point2d(0, 0));

const boundary = new HatchBoundaryPaths();
// Add the defined path
boundary.addPolylineBoundary(polyline, PolylineFlags.External);
boundary.addPolylineBoundary(polyline1, PolylineFlags.Outermost);

const mysolid = pattern({
    name: HatchPredefinedPatterns.SOLID,
    // scale: 0.05,
    // angle: 287.89,
    // Other properties you can define optionally
    // angle?: number;
    // scale?: number;
    // double?: boolean;
});

const hatch = dxf.addHatch(boundary, mysolid);

Stringify Performance

Hi,

for some automation stuff i am working on, i did a quick test-run of your very nice package.
My intention is to compose a DXF from several sub-drawings, which already works nicely.
These sub-drawings can become quite detailed, though.
My current test-setup parses and inserts entities from an 8MB DXF into an instance of your writer class, which is real quick.

However, for the final write-to-disc, i need to stringify(), which unfortunately takes about 30sec.

Do you think there's a way of speeding things up here?

Property 'addImageDef' does not exist on type 'DxfWriter'

I'm using this package in a typescript project and i'm not able to use .addImageDef

I'm getting the error

Property 'addImageDef' does not exist on type 'DxfWriter'

Below is the screenshot - in the screenshot this.exporter is the DxfWriter

image

Add support for `Hatch` entity

  • Implement Hatch class ๐ŸŽ‰
  • Add support for hatching entities already existing directly ๐ŸŽ‰
  • Support all predefined patterns ๐ŸŽ‰
  • Support all type of hatches ๐ŸŽ‰
  • Adding tests ๐ŸŽ‰

ObjectARX Problem

Could you help me out with .net objectArx ??

I would like to create a layout with 6 views in it(Top, Front, Left, Right, Bottom , Back ). The views should fit in the viewports accurately and the visual style be hidden. The views should be black in color so that i can view them when exported. Finally export the pdf.

ObjectARX code:

private static void StyleViewport(Autodesk.AutoCAD.DatabaseServices.Viewport viewport)
{
using (Database db = HostApplicationServices.WorkingDatabase)
{
using (Transaction tr = db.TransactionManager.StartTransaction())
{
// "Hidden" is the name of the visual style you want
viewport.VisualStyleId = GetVisualStyleId(db, "Hidden");

// Set other properties if needed
viewport.Color = Autodesk.AutoCAD.Colors.Color.FromRgb(0, 0, 0);

tr.Commit();
}
}
}

[CommandMethod("InsertViewsToLayout")]
public static void InsertViewsToLayout()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Database acCurDb = acDoc.Database;

using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable;

BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.PaperSpace], OpenMode.ForWrite) as BlockTableRecord;

// Switch to the previous Paper space layout
Application.SetSystemVariable("TILEMODE", 0);
acDoc.Editor.SwitchToPaperSpace();

// Get the current layout
LayoutManager acLayoutMgr = LayoutManager.Current;
Layout acLayout = acTrans.GetObject(acLayoutMgr.GetLayoutId(acLayoutMgr.CurrentLayout), OpenMode.ForWrite) as Layout;

Point3d[] viewPositions = {
new Point3d(2.5, 5.5, 0),
new Point3d(2.5, 2.5, 0),
new Point3d(5.5, 5.5, 0),
new Point3d(5.5, 2.5, 0),
new Point3d(8.5, 5.5, 0),
new Point3d(8.5, 2.5, 0)
};

Vector3d[] viewDirections = {
new Vector3d(0, 0, -1),
new Vector3d(0, 0, 1),
new Vector3d(-1, 0, 0),
new Vector3d(1, 0, 0),
new Vector3d(0, -1, 0),
new Vector3d(0, 1, 0)
};

for (int i = 0; i < viewPositions.Length; i++)
{
using (Autodesk.AutoCAD.DatabaseServices.Viewport acVport = new Autodesk.AutoCAD.DatabaseServices.Viewport())
{
acVport.CenterPoint = viewPositions[i];
acVport.Width = 2.5;
acVport.Height = 2.5;

// Add the new viewport to the layout's block table record
acBlkTblRec.AppendEntity(acVport);
acTrans.AddNewlyCreatedDBObject(acVport, true);

// Set the view direction
acVport.ViewDirection = viewDirections[i];

// Set the visual style
StyleViewport(acVport);

// Enable the viewport
acVport.On = true;
}
}

acTrans.Commit();
acDoc.Editor.Regen();
}
}

Here's my code:
Error is :
Severity Code Description Project File Line Suppression State
Error CS0103 The name 'GetVisualStyleId' does not exist in the current context AutoCad C:\Users\source\repos\AutoCad\AutoCad\Commands.cs 268 Active

i am trying a lot but unable to figure out the solution.
Please resolve my issue.

You can also modify approach of viewports, You can insert views using "Base->Model Space" that way...

Cannot customize entities

We need to be able to customize entities.

  • Set different color.
  • Set true color.
  • Set thickness and so on ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.