Author Topic: Lsp2Arx ang_dec function  (Read 3890 times)

0 Members and 1 Guest are viewing this topic.

LE

  • Guest
Lsp2Arx ang_dec function
« on: November 27, 2005, 08:56:50 PM »
I am working translating some of my lisp function into arx, here is ang_dec function, that's calculate the delta, have a look and would like to hear if that's how you would write the function/translation or if it is a better way.... I like to know!.

Hope that makes some sense.
« Last Edit: November 29, 2005, 11:08:25 PM by LE »

LE

  • Guest
Re: Lsp2Arx ang_dec function
« Reply #1 on: November 27, 2005, 10:51:51 PM »
Something is not right with the code... I'll post it back again....

Chuck Gabriel

  • Guest
Re: Lsp2Arx ang_dec function
« Reply #2 on: November 28, 2005, 07:52:50 AM »
I would change the return type to Acad::ErrorStatus and have the function return a value indicating success or failure.

LE

  • Guest
Re: Lsp2Arx ang_dec function
« Reply #3 on: November 28, 2005, 10:44:33 AM »
I would change the return type to Acad::ErrorStatus and have the function return a value indicating success or failure.

I think I got this running Chuck, thank you.... I end up using the calls inside of one of my methods instead of as a general function.... for now.

Also, I am noticed, that the call of acedGetEnv does not work this:
Code: [Select]
char* var;
if (acedGetEnv("ArcDrawAngleInput",var) != RTNORM) {
acedSetEnv("ArcDrawAngleInput","1");
}

I end up using this:
Code: [Select]
const char* var;
var = acdbHostApplicationServices()->getEnv("ArcDrawAngleInput");
std::string strVar(var);

acutPrintf("ArcDrawAngleInput %s\n", strVar.c_str());

if (atoi(strVar.c_str())==1) {

My question will be, why ?.... I supposed was making the calls right... or was late last night no coffee or age?....

Quote
int
acedGetEnv(
const char * sym,
char * var);

sym Input environment variable name to get, which is case sensitive in all environments (Visual LISP, ObjectARX, and VB/ActiveX)
var Output preallocated buffer to be filled in with environment variable value (a buffer size of 1024 bytes should be sufficient)

Thanks.
« Last Edit: November 28, 2005, 10:50:42 AM by LE »

Chuck Gabriel

  • Guest
Re: Lsp2Arx ang_dec function
« Reply #4 on: November 28, 2005, 01:22:24 PM »
According to the blurb you quoted from the help, you need to initialize your char* var to point to a valid buffer.

You could have done either:

// buffer on the stack
char var[1024];

or

// buffer on the heap
char* var = new char[1024];
// do your stuff
delete[] var;

LE

  • Guest
Re: Lsp2Arx ang_dec function
« Reply #5 on: November 28, 2005, 11:46:55 PM »
Here is the latest about the function ang_dec in lsp and arx

Code: [Select]
(defun ang_dec (/ grad mnt seg uniang)
  (if (not (getenv "ArcDrawAngleInput"))
    (setenv "ArcDrawAngleInput" "1"))
  (setq uniang (atoi (getenv "ArcDrawAngleInput")))
  (if (null uniang)
    (setq uniang 1))
  (if (= uniang 1)
    (progn (setq grad (getreal "\nDegrees: ")
mnt  (getreal "\nMinutes: ")
seg  (getreal "\nSeconds: " ))
   (+ grad (/ mnt 60.0) (/ seg 3600.0)))
    (setq grad (* (/ (getreal "\nDecimal degrees: ") 400) 360))))
Code: [Select]
static ads_real ang_dec()
{
ads_real delta;
char var[1024];
if (acedGetEnv("ArcDrawAngleInput",var) != RTNORM) {
acedSetEnv("ArcDrawAngleInput","1");
acedGetEnv("ArcDrawAngleInput",var);
}
switch (atoi(var)) {
case 1:
acutPrintf("\nAngle input format: DMS [sexagesimal]\n");
ads_real grad,mnt,seg;
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nDegrees: ",&grad)==RTNORM) {
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nMinutes: ",&mnt)==RTNORM) {
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nSeconds: ",&seg)==RTNORM) {
delta=grad+mnt/60.0+seg/3600.0;
return delta;
}//if seconds
}//if minutes
}//if degrees
else {return FALSE;}
break;
case 0:
acutPrintf("\nAngle input format: Decimal Degrees [centesimals]\n");
ads_real decDeg;
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nDecimal degrees: ",&decDeg)==RTNORM){
delta=decDeg/400*360;
return delta;
}//if decimal degrees
else {return FALSE;}
break;
}
}
« Last Edit: November 29, 2005, 11:11:51 PM by LE »

LE

  • Guest
Re: Lsp2Arx ang_dec function
« Reply #6 on: December 01, 2005, 09:57:08 PM »
Some pecata minuta.... I know no one noticed:

Code: [Select]
int ang_dec(ads_real delta) {
char var[1024];
if (acedGetEnv("ArcDrawAngleInput",var) != RTNORM) {
acedSetEnv("ArcDrawAngleInput","1");
acedGetEnv("ArcDrawAngleInput",var);
}
switch (atoi(var)) {
case 1:
acutPrintf("\nAngle input format: DMS [sexagesimal]\n");
ads_real grad,mnt,seg;
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nDegrees: ",&grad)==RTNORM) {
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nMinutes: ",&mnt)==RTNORM) {
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nSeconds: ",&seg)==RTNORM) {
delta=grad+mnt/60.0+seg/3600.0;
return TRUE;
}//if seconds
}//if minutes
}//if degrees
else {return FALSE;}
break;
case 0:
acutPrintf("\nAngle input format: Decimal Degrees [centesimals]\n");
ads_real decDeg;
acedInitGet(RSG_NONEG,"");
if (acedGetReal("\nDecimal degrees: ",&decDeg)==RTNORM){
delta=decDeg/400*360;
return TRUE;
}//if decimal degrees
else {return FALSE;}
break;
}
}

Then it can be use like:

Code: [Select]
ads_real delta;
if (ang_dec(delta)==TRUE) {