明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 2763|回复: 17

大侠哥哥们请帮忙 小妹快哭出来了

  [复制链接]
发表于 2004-11-2 16:12:00 | 显示全部楼层 |阅读模式
本帖最后由 作者 于 2004-11-3 11:11:53 编辑

我就想从文件里面读出x,y坐标,然后循环画点。可是我这样写根本画不出来。要是我把读文件那段函数写在drawplanestation()主程序里,在运行cad时,就说我犯了致命的错误。各位大哥快请帮帮小妹我吧!!

void initApp()
{
acedRegCmds->addCommand("drawplanestation_COMMAND",
"planestation",
"1",
ACRX_CMD_TRANSPARENT,
drawplanestation);

} double xx[300],yy[300];
int i=0;
void read_data()
{
FILE *fp;
float px,py,pz;
fp=fopen("planestation1.txt","wr");
char x[20],y[20];
while(!feof(fp))
{
if (fscanf(fp,"%s%s",x,y)==EOF)
break;
xx=atof(x);
yy=atof(y);


i=i+1;
}
fclose(fp);

}
void drawplanestation()
{
AcDbObjectIdArray idArray;
float px,py,pz;
read_data();

for (i=0;i<293;i++)
{
px=xx;
py=yy;
pz=100;
idArray.append(createPoint3D(px,py,pz));
}

}
AcDbObjectId createPoint3D(float l,float m,float n)
{ AcGePoint3d p(l,m,n);
AcDbPoint *po= new AcDbPoint(p);
po->setColorIndex(3);
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable,AcDb::kForWrite);
AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE,pBlockTableRecord,AcDb::kForWrite);
pBlockTable->close();
AcDbObjectId pointId;
pBlockTableRecord->appendAcDbEntity(pointId,po);
po->close();
pBlockTableRecord->close();
return pointId;
delete [] po; } void unloadApp()
{
acedRegCmds->removeGroup("drawplanestation_COMMAND"); }
发表于 2004-11-2 22:50:00 | 显示全部楼层

回复

请把你的坐标文件也贴上来吧!
 楼主| 发表于 2004-11-3 10:47:00 | 显示全部楼层
谢谢这位版主,以下是文件内容:左边是x坐标,右边是y坐标。 7177.54 8975.06
6486.46 8558.98
7241.46 9244.35
6629.36 8323.66
6389.57 8720.73
6760.03 8492.40
7389.53 8635.84
6727.32 8934.57
6619.62 9107.85
6565.24 8842.17
6937.04 8588.78
7116.02 8268.71
7001.96 8866.86
6892.92 9047.06
7202.50 8533.59
7070.08 9141.08
7606.89 9023.53
7720.54 8836.88
7858.92 9382.80
7051.94 8780.26
7159.22 8604.76
7328.41 8712.71
7229.33 8876.16
7758.29 8387.43
7196.83 8836.67
7183.15 8859.02
7155.86 8904.78
7142.26 8924.19
7105.08 8988.20
7090.93 9009.62
7262.91 8820.55
7249.81 8841.22
7210.90 8909.16
7185.10 8953.83
7149.31 9010.20
7131.58 9033.99
7162.33 8696.37
7149.78 8716.47
7137.76 8736.38
7120.03 8759.59
7113.38 8781.51
7094.96 8805.77
7085.85 8828.52
7070.26 8850.24
7057.74 8871.39
7043.77 8895.25
7032.93 8914.90
7017.59 8934.95
7006.92 8953.83
6993.28 8978.11
7165.97 8789.69
7113.70 8877.26
7098.63 8897.51
7060.05 8961.23
7047.51 8982.30
7033.58 9005.29
7020.83 9025.35
7318.03 8828.10
7306.41 8846.38
7293.89 8866.23
7280.44 8889.27
7253.33 8930.19
7241.60 8948.74
7214.10 8998.73
7200.99 9019.56
7190.29 9038.70
7177.06 9059.38
7372.24 8831.67
7336.80 8894.66
7323.55 8913.47
7296.17 8956.02
7268.97 9001.35
7026.59 8734.44
7010.64 8755.21
6999.63 8774.87
6974.39 8817.50
6958.36 8841.87
6932.17 8885.10
6920.84 8905.81
6907.29 8925.11
7042.95 8803.90
7028.21 8825.49
7016.46 8846.10
6975.66 8910.56
7009.24 8573.57
6992.62 8596.37
6966.82 8638.96
6942.75 8680.25
6887.61 8767.15
7049.02 8601.49
7035.81 8623.73
7009.39 8665.22
6995.51 8686.72
6980.98 8708.59
6956.68 8750.58
6903.63 8835.45
6889.70 8857.43
6877.25 8878.00
6829.20 8671.60
6785.79 8735.76
6737.08 8819.96
6725.49 8842.20
6710.51 8862.40
6884.57 8679.04
6870.91 8697.00
6844.32 8740.41
6815.58 8784.26
6792.35 8825.10
6750.85 8892.88
6786.85 8645.16
6747.00 8707.91
6720.73 8751.80
6705.15 8769.94
6694.57 8797.80
6668.05 8836.16
6654.39 8856.88
7531.97 8373.88
7479.53 8458.38
7201.69 8922.78
7588.81 8290.85
7128.17 8059.51
7756.28 8972.54
7704.90 9059.80
7650.98 9135.73
7189.00 8746.34
7137.22 8831.31
7080.28 8923.83
7019.64 8057.93
6916.39 8229.38
6807.80 8403.62
6874.64 8316.65
6653.22 8649.26
6508.60 8910.55
7915.36 8958.11
7987.59 8764.88
7931.54 8852.21
7856.05 9018.64
7740.64 9187.92
7677.11 9286.01
6931.02 8012.21
6883.18 8090.82
6830.76 8177.18
6779.39 8262.66
6729.22 8347.38
6674.78 8434.74
6622.04 8521.46
6569.85 8605.29
6498.50 8700.99
6404.07 8784.82
6421.50 8874.77
6797.00 8040.56
6744.98 8125.10
6701.92 8216.77
6658.47 8274.72
6539.25 8471.05
6440.33 8627.68
6330.42 8812.30
6905.74 7869.93
8150.84 8869.44
8121.02 8952.74
8016.77 9121.10
7907.44 9288.44
7965.24 9216.54
7465.96 8678.80
7409.65 8758.64
7354.88 8857.09
7311.20 8936.34
7252.82 9025.87
6939.83 8951.64
7107.63 8692.76
7264.18 8443.96
7346.93 8292.08
7317.18 8355.59
7778.73 9098.82
7415.37 8179.79
8063.30 9045.40
7268.71 8787.37
6708.90 8587.88
7990.09 8401.68
7591.86 8664.37
7715.48 8480.86
7652.04 8561.84
7549.99 8730.31
7303.03 9159.09
7501.23 8815.36
7390.08 9002.59
7449.70 8894.49
7347.31 9062.01
7226.72 8298.19
7170.39 8383.91
7123.82 8465.23
7070.42 8557.39
7022.98 8640.64
6966.20 8728.04
6913.11 8811.98
6862.45 8904.93
6804.20 8996.26
6759.76 9073.73
7276.75 8213.25
7330.74 8126.05
7792.14 8524.44
7740.21 8611.09
7685.00 8689.73
7632.34 8783.02
7823.76 8673.90
7530.46 8955.63
7477.80 9036.83
7422.46 9124.72
7377.64 9206.17
7582.75 8866.20
7441.77 8533.05
7193.11 8163.88
7089.04 8330.19
6993.36 8506.79
6889.49 8666.24
6594.04 8802.04
6776.40 8853.68
6683.87 9025.04
6829.99 8761.60
7029.76 8434.31
7234.46 8089.97
7879.19 8573.93
7566.18 9083.46
7929.51 8488.66
7776.72 8740.90
7669.56 8916.35
7513.15 9177.65
7106.05 8111.89
7054.98 8196.68
7000.04 8289.00
6942.00 8372.45
6893.36 8455.60
6836.56 8532.65
6793.43 8623.79
6757.45 8692.25
6684.99 8811.99
6635.27 8898.98
6582.07 8981.41
6542.32 9054.80
6931.04 8692.59
6899.04 8741.82
6870.17 8793.61
6814.55 8691.86
6741.94 8807.84
6938.51 8766.45
6859.88 8707.46
6806.26 8801.40
6729.90 8743.15
6608.42 9166.49
6498.89 9078.27
6466.31 8946.23
6396.74 8919.14
6256.63 8831.46
6348.03 8693.01
6397.95 8598.04
6440.19 8537.13
6500.50 8437.57
6584.85 8295.16
6610.76 8251.91
6659.77 8183.20
6701.99 8105.15
6758.12 8013.92
6938.17 7725.47
6975.30 7982.87
7032.99 8009.13
7139.73 8015.45
7250.43 8040.48
7350.63 8081.69
7438.95 8135.45
7613.24 8247.96
7796.66 8357.16
7823.92 8444.51
8033.32 8306.06
8035.26 8742.03
8218.32 8855.05
8164.36 8975.97
8102.70 9075.44
8053.44 9151.07
8001.10 9241.14
7954.16 9321.72
7871.04 9450.25
7634.68 9320.75
7609.58 9201.69
7521.68 9226.93
7386.18 9253.02
7182.33 9315.87
7204.69 9083.62
6991.51 9276.94
7027.21 9078.35
6998.18 9085.89
6974.68 9051.50
6917.61 9096.88
6762.40 9121.97
发表于 2004-11-3 10:56:00 | 显示全部楼层
你单步调试试试看,数组有没有读对值?
 楼主| 发表于 2004-11-3 11:07:00 | 显示全部楼层
在Arx框架下,我不会单步调试。我在mfc框架下调试过,可以读。


请问怎样设断点调试呀,在Arx框架下?一按执行就调出cad界面了。
发表于 2004-11-3 11:07:00 | 显示全部楼层
double xx[300],yy[300]; 重復定义两次!! read_data()函数里面把外面的定义隐藏了!! 外面数据为空!! for (i=0;i<293;i++)
{
px=xx;
py=yy;
pz=100;
idArray.append(createPoint3D(px,py,pz));
}
执行时就出错了
 楼主| 发表于 2004-11-3 11:23:00 | 显示全部楼层
easypower gg ;我把read_data()里面的xx,yy去掉了,还是画不出来。编译没有错,可就是在cad里不出现图。
发表于 2004-11-3 12:44:00 | 显示全部楼层
delete [] po;去掉
 楼主| 发表于 2004-11-3 13:04:00 | 显示全部楼层
power gg;还是 调试没有错,cad不出图,会不会是我的软件装得有问题?


要不在你的机器上先运行一下看看?
发表于 2004-11-3 13:38:00 | 显示全部楼层

回复

参考: static void CreatePointFromTxtFile_cp(void)
{
// Add your code for command CreatePointFromTxtFile._cp here
CFileFind finder;
CString txtFile = "C:\\1.txt";
if (finder.FindFile(txtFile) != TRUE)
{
acedAlert("txt文件不存在!");
return;
}
CStdioFile dataStore;
CString somecode; BOOL bIsOk = dataStore.Open(txtFile, CFile::modeRead | CFile::shareDenyWrite | CFile::typeText);
if (!bIsOk) return; AcGePoint3dArray pointArray;
AcGePoint3d pt; while (dataStore.ReadString(somecode) != NULL)
{
somecode.TrimLeft(_T(" "));
somecode.TrimRight(_T(" "));
CString x;
CString y;
x = somecode.Left(somecode.Find(_T(" ")));
y = somecode.Mid(somecode.Find(_T(" "))).Trim();
//acedAlert(x);
//acedAlert(y);
pt.x = atof(x);
pt.y = atof(y);
pt.z = 0.0;
pointArray.append(pt);
} for (int i = 0; i < pointArray.length(); i++)
{
pt.set(pointArray.x, pointArray.y, 0.0); AcDbPoint* ptObj = new AcDbPoint;
ptObj->setPosition(pt);
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pBlockTable, AcDb::kForRead); AcDbBlockTableRecord *pBlockTableRecord;
pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord, AcDb::kForWrite);
pBlockTable->close(); AcDbObjectId ptId;
pBlockTableRecord->appendAcDbEntity(ptId, ptObj); pBlockTableRecord->close();
ptObj->close();
}
} 文本文件: "c:\\1.txt" 结果: 源程序:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

x
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-26 10:26 , Processed in 0.189306 second(s), 25 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表