.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Inserting blocks with value for y=0 from CSV flie.

7 REPLIES 7
Reply
Message 1 of 8
chikito1990
622 Views, 7 Replies

Inserting blocks with value for y=0 from CSV flie.

Hi all,

 

I am trying to insert some blocks that i read from CSV file. I am reading the values for X and Y position from a CSV file and inseting blocks with this values in AutoCAD. 

Here is my code:

[CommandMethod("BI_5")]
        public void BlockInsert_5()
        {
            String filePath="C:\\Users\\Dimitar\\Desktop\\imp.csv";
            CsvDoc csv = new CsvDoc(filePath, true);

            for (int i = 0; i < csv.Data.Count; i++)
            {

                string blockQualifiedFileName = csv.Get<string>(i, "Block Path");
                double scale = 3.0;
                Vector3d DispacementVector = new Vector3d(Double.Parse(csv.Get<string>(i, "PosX")), Double.Parse(csv.Get<string>(i, "PosY")), 0);
                //
                Database tmpDb = new Database(false, true);
                tmpDb.ReadDwgFile(blockQualifiedFileName, System.IO.FileShare.Read, true, "");

                Matrix3d Transform = ed.CurrentUserCoordinateSystem;

                Transform = Transform *
                    Matrix3d.Scaling(scale, Point3d.Origin) *
                    Matrix3d.Displacement(DispacementVector / scale);

                db.Insert(Transform, tmpDb, true);
            }
        }

One of the values for Y is 0. And the block instead of showing on X,0 it shows at some X,Y value. Can you please help me? If you need to see the csv file I can upload it. Thank you in advance.

 

Best regards,

Dimitar Georgiev

Tags (3)
7 REPLIES 7
Message 2 of 8
_gile
in reply to: chikito1990

Hi,

 

Take care about the order you multiply matrices (the matrix multiplication is not commutative).

 

pt.TransformBy(m1 * m2);

 

is the same as:

 

pt.TransformBy(m2).TransformBy(m1);



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 3 of 8
chikito1990
in reply to: _gile

Thanks for the answer but can you please explain a little bit more because i am still new in AutoCAD development?

 

Thanks in advance.

Tags (3)
Message 4 of 8
_gile
in reply to: chikito1990

when you do:

Transform = ed.CurrentUserCoordinateSystem *
    Matrix3d.Scaling(scale, Point3d.Origin) *
    Matrix3d.Displacement(DispacementVector / scale);

 it the same as if you sequentialy first move the block, then scale it and then translate to UCS.

 



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 5 of 8
chikito1990
in reply to: _gile

So I have to create ne vector3d, multiply it by the scale and then make it equal to the UCS? I am sorry that i am asking this stupid questions but i just started to learn. If you can explain it I will be very glad.

 

Thnak you in advance.

Message 6 of 8
chikito1990
in reply to: chikito1990

I change it to:

Transform = Transform *
                Matrix3d.Displacement(DispacementVector) *
                Matrix3d.Scaling(scale, Point3d.Origin);

 but still the block that  has value 0 for the Y axcis is not on the zero point its lets say with 400 ucs upper form the zero

Tags (3)
Message 7 of 8
_gile
in reply to: chikito1990

Perhaps you'd rather explain what you're trying to achieve.



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

Message 8 of 8
chikito1990
in reply to: _gile

Ok,

 

I have a CSV file with blocknames, positionX and positionY fields.

 

I am reading the file and inserting the blocks. The problem is that the blocks are coming from software where the UCS is set to be on top left part of the screen and the AutoCAD UCS are bottom left. So I have to mirror the image so it can look the same as the original. I am taking the most high number for the height point(positionY) from the existing values and subtracting it from all other values and then I have one element which is with height point 0(meaning positionY=0). I am reading the values and inserting the blocks. All look perfect only one is not on its place it has some value for positionY which does not exist in the value list for positionY. Any ideas why this is happening?

 

Best regards,

Dimitar Georgiev

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost