Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't create block successfully #23

Open
Dynabits opened this issue Nov 19, 2021 · 3 comments
Open

Can't create block successfully #23

Dynabits opened this issue Nov 19, 2021 · 3 comments

Comments

@Dynabits
Copy link

Every Time ACAD 2018 crashes with the generated file from this code:

    let mut drawing = Drawing::new();

    let point = ModelPoint::default();
    let point = Entity::new(EntityType::ModelPoint(point));
    // drawing.add_entity(point);

    let mut att = AttributeDefinition::default();
    att.text_tag = String::from("tag");
    att.prompt = String::from("tag_prompt");
    att.value = String::from("test_value");
    att.value = String::from("1");
    let att = Entity::new(EntityType::AttributeDefinition(att));
    // drawing.add_entity(att);

    let mut lyr1 = Layer::default();
    lyr1.name = String::from("layer1_test");
    drawing.add_layer(lyr1);

    let mut blc = Block::default();
    blc.name = String::from("blc_name");
    blc.set_has_non_consistent_attribute_definitions(true);
    let mut vec = Vec::new();
    vec.push(att);
    vec.push(point);
    blc.entities = vec;
    drawing.add_block(blc);

    drawing.save_file("test.dxf").ok();

I think I'm not creating the block correctly, the goal is to have the point and the attribute entities inside the block.

Any help would be very appreciated.

PS: I'm new to rust and dxf spec.

@brettfo
Copy link
Member

brettfo commented Nov 19, 2021

AutoCAD is extremely pick about what it will accept, and frankly I haven't figured out the exact formula yet. That said, other CAD apps are less strict and LibreCAD will open the following DXF with a block:

let mut drawing = Drawing::new();

// this creates a block with a single line from (0,0) to (1,1)
// n.b., the block will not yet be displayed on screen; it exists simply as a "template" that can be inserted later
let mut block = Block::default();
block.name = String::from("block_name");
block.entities.push(Entity::new(EntityType::Line(Line::new(
    Point::new(0.0, 0.0, 0.0),
    Point::new(1.0, 1.0, 0.0),
))));
drawing.add_block(block);

// this inserts a copy of the "block_name" block at location (2,2)
// the result of this is a line from (2,2) to (3,3)
let mut ins = Insert::default();
ins.name = String::from("block_name");
ins.location = Point::new(2.0, 2.0, 0.0);
let ins = Entity::new(EntityType::Insert(ins));
drawing.add_entity(ins);

// this inserts a copy of the "block_name" block at location (2,-2)
// the result of this is a line from (2,-2) to (3,-1)
let mut ins = Insert::default();
ins.name = String::from("block_name");
ins.location = Point::new(2.0, -2.0, 0.0);
let ins = Entity::new(EntityType::Insert(ins));
drawing.add_entity(ins);

drawing.save_file("test.dxf").ok();

@Dynabits
Copy link
Author

@brettfo thank you for your reply and example code, when I run it, the same result ACAD say it's invalid drawing.

Maybe someone like you with the required expertise can look at other libraries like link and see what could be the problem?

@brettfo
Copy link
Member

brettfo commented Nov 29, 2021

@Dynabits Thank you for that link, I hadn't seen that before and it was very helpful.

I've pushed commit 944f6e4 to main which will write a BLOCK/INSERT in R12 and I can then open it in AutoCAD 2016 (that's the only version I have to test with.)

That commit also contains the file examples/src/block_examples.rs which should get you started.

I'll start testing R13+ and see what I can come up with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants