.NET

Reply
Active Contributor
chikito1990
Posts: 40
Registered: ‎06-26-2013
Message 1 of 8 (268 Views)

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

268 Views, 7 Replies
07-23-2013 03:42 AM

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

*Expert Elite*
_gile
Posts: 2,114
Registered: ‎04-29-2006
Message 2 of 8 (251 Views)

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

07-23-2013 05:24 AM 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
Active Contributor
chikito1990
Posts: 40
Registered: ‎06-26-2013
Message 3 of 8 (248 Views)

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

07-23-2013 05:45 AM 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.

*Expert Elite*
_gile
Posts: 2,114
Registered: ‎04-29-2006
Message 4 of 8 (238 Views)

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

07-23-2013 06:04 AM 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
Active Contributor
chikito1990
Posts: 40
Registered: ‎06-26-2013
Message 5 of 8 (230 Views)

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

07-23-2013 06:24 AM 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.

Active Contributor
chikito1990
Posts: 40
Registered: ‎06-26-2013
Message 6 of 8 (227 Views)

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

07-23-2013 06:28 AM 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

*Expert Elite*
_gile
Posts: 2,114
Registered: ‎04-29-2006
Message 7 of 8 (191 Views)

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

07-23-2013 09:36 AM in reply to: chikito1990

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

Gilles Chanteau
Active Contributor
chikito1990
Posts: 40
Registered: ‎06-26-2013
Message 8 of 8 (171 Views)

Re : Inserting blocks with value for y=0 from CSV file.

07-24-2013 12:49 AM 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

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!