InsertBlock using Embarcadero C++

InsertBlock using Embarcadero C++

Anonymous
Not applicable
1,307 Views
7 Replies
Message 1 of 8

InsertBlock using Embarcadero C++

Anonymous
Not applicable

Trying to write a program in C++ that will allow me to insert a dwg file into and existing template.  I am using the ObjectArx library compiled for C++.

My error I am revceiving seems to relate to the varriant array needed to pass into the insertblock function.  

Actual error is "First chance exception at $007FEABD. Exception class $C0000096 with message 'Privileged instruciton at 0x007feabd'"

 

Snippet of my code

#include "AutoCAD_TLB.h"
#include "AutoCAD_OCX.h"

void __fastcall Std_Print()

{

VARIANT insertionPnt[3];

 String Path1

 Path1 = "D:\\TL\\ Paper\\'n";

insertionPnt[0].intVal = 0.0; // x

insertionPnt[1].intVal = 0.0; // y
insertionPnt[2].intVal = 0.0; // z

 

blockRefObj = acadDoc->PaperSpace->InsertBlock(insertionPnt[3], Path1.c_str(), 1.0, 1.0, 1.0, 0.0);

blockRefObj->Explode();
blockRefObj->Erase();

 

}

 

Any help would be appreciated.

0 Likes
1,308 Views
7 Replies
Replies (7)
Message 2 of 8

owenwengerd
Advisor
Advisor

In your code, insertionPnt[3] attempts to access the 4th element of a 3-element array.

--
Owen Wengerd
ManuSoft
0 Likes
Message 3 of 8

tbrammer
Advisor
Advisor

Embarcadero C++ is not a supported IDE for ARX development.

You should use Visual Studio with a version that depends on your AutoCAD target version.

 

However - if you are interacting with AutoCAD via COM out of proc only it could be possible to use a different compiler. I never tried.

Can you post a complete simplified project?

 


Thomas Brammer ● Software Developer ● imos AGLinkedIn
If an answer solves your problem please [ACCEPT SOLUTION]. Otherwise explain why not.

0 Likes
Message 4 of 8

Anonymous
Not applicable

I tried to attach a complete project simulation of what I am doing in my program this gets you to point where I get stuck, but the file size was to large.

Here is a link to the files.

https://drive.google.com/folderview?id=0B9o1gxIA8hvNQTlUaWFiUGR2S3c&usp=sharing

 

Let me know if this helps or I can add more details.  Thank you for your time.

 

I am trying to import a dwg to autocad 2015 64 bit.  I noticed I left that detail out.  I have not tried doing this in any other version of autocad.

I am not familiar with the autocad via com.  I will do some looking into that.  Thanks.

 

 

0 Likes
Message 5 of 8

Anonymous
Not applicable
Hi,
It's been a while since I used COM but as far as I remember, you should have a look to SAFEARRAY and BSTR to pass arrays of variants and strings as arguments to COM APIs.
You'll have to take care of properly allocate them (using ::AllocSysString for strings and ... I don't remember for safearrays)
Sorry, I'm not able to help you much, I don't have my computer right now, I guess Google will be your friend there!
I hope this helps
Message 6 of 8

Anonymous
Not applicable
Thanks for the information, at this point I am at a loss so any bits of info will hopefully get me farther to completing this project. Thanks.
0 Likes
Message 7 of 8

Anonymous
Not applicable

You are correct I wasn't handling the passing of a variant correctly.

I have posted similar question on another forum as well.

https://forums.embarcadero.com/thread.jspa?threadID=118888&tstart=0

I was giving several ideas on how to handle the Variant Array below is one way that was suggested for me to handle the problem.

 

#include "AutoCAD_TLB.h"
#include "AutoCAD_OCX.h"
 
{
    DOUBLE insertionPnt[3];
    insertionPnt[0] = 0.0;    // x
    insertionPnt[1] = 0.0;    // y
    insertionPnt[2] = 0.0;    // z
 
    VARIANT varInsertionPnt;
    if (InitVariantFromDoubleArray(insertionPnt, 3, &varInsertionPnt) == 
S_OK)
    {
        WideString Path1 = L"D:\\FileName'n";
        blockRefObj = acadDoc->ModelSpace->InsertBlock(varInsertionPnt, Path1.c_bstr(), 
1.0, 1.0, 1.0, 0.0);
        blockRefObj->Explode();
        blockRefObj->Erase();
    }
}

I did implment this and I am now getting an error from 

 OLECHECK(this->get_ModelSpace(&PMSpace));

This is part of the ObjectARX Library.  I still get an access violation at this point, it is still running the function insertblock when it throws an error.  I have tried with both autocad open and closed to see if it was having an issue retrieving a process id or application name.  Not sure why its failing at this point.  Thanks for your help  owenwengerd.

0 Likes
Message 8 of 8

Anonymous
Not applicable

Anyone had time to look at this any further or having any other suggestions I can try. Thanks

0 Likes