正常导入可以观看

https://v.youku.com/v_show/id_XMjczNjMzMDE2OA==.html?from=y1.7-2&spm=a2hzp.8253869.0.0#paction

文字方法参考如下

https://jingyan.baidu.com/article/48b558e326e1b17f39c09a57.html

错误处理使用下面

注意代码的178行,这是这篇文章处理.bxl文件导入的关键

//通过修改上面这行中的分隔符,同时在执行过程中屏蔽   Model := STEPmodel.ModelFactory_FromFilename(STEPFileName, false);    再打开这行 就可生成封装库


{==============================================================================}
{====  String Utility Routines  ===============================================}
{==============================================================================}Function CheckLeft(BaseStr: String, Srch: String): Boolean;
Vari : Integer;
BeginResult := False;i := Length(Srch);If Length(BaseStr) < i Then Exit;If Copy(BaseStr, 1, i) = Srch Then Result := True;
End;Function LeftOf(BaseStr: String, Srch: String): String;
Vari : Integer;
Begini := Pos(Srch, BaseStr);If i > 0 Then BeginResult := Copy(BaseStr, 1, i - 1);End Else BeginResult := BaseStr;End;
End;Function RightOf(BaseStr: String, Srch: String): String;
Vari, ls : Integer;
Begini := Pos(Srch, BaseStr);If i > 0 Then Beginls := Length(Srch);Result := Copy(BaseStr, i + ls, Length(BaseStr) - i + ls);End Else BeginResult := '';End;
End;Procedure StrChop(BaseStr: String, Srch: String, Out LeftSide: String, Out RightSide: String);
Vari, ls : Integer;
Begini := Pos(Srch, BaseStr);If i <= 0 Then BeginLeftSide := BaseStr;RightSide := '';End Else Beginls := Length(Srch);LeftSide := Copy(BaseStr, 1, i - 1);RightSide := Copy(BaseStr, i + ls, Length(BaseStr) - i + ls);End;
End;Function GetBetween(BaseStr: String, StartStr: String, EndStr: String): String;
BeginResult := Leftof(RightOf(BaseStr, StartStr), EndStr);
End;Function GetFileLocation(FilePath: String): String;
Vari : Integer;filename : String;
Beginfilename := RightOf(FilePath, '\');i := Pos('\', filename);While i > 0 Do Beginfilename := RightOf(filename, '\');i := Pos('\', filename);End;Result := LeftOf(Filepath, filename);
End;{==============================================================================}
{====  Footprint Routines  ====================================================}
{==============================================================================}Function LayerFromString(LName: String): TLayer;
BeginCase LName Of'NoLayer':         Result := eNoLayer;'TopLayer':        Result := eTopLayer;'MidLayer1':       Result := eMidLayer1;'MidLayer2':       Result := eMidLayer2;'MidLayer3':       Result := eMidLayer3;'MidLayer4':       Result := eMidLayer4;'MidLayer5':       Result := eMidLayer5;'MidLayer6':       Result := eMidLayer6;'MidLayer7':       Result := eMidLayer7;'MidLayer8':       Result := eMidLayer8;'MidLayer9':       Result := eMidLayer9;'MidLayer10':      Result := eMidLayer10;'MidLayer11':      Result := eMidLayer11;'MidLayer12':      Result := eMidLayer12;'MidLayer13':      Result := eMidLayer13;'MidLayer14':      Result := eMidLayer14;'MidLayer15':      Result := eMidLayer15;'MidLayer16':      Result := eMidLayer16;'MidLayer17':      Result := eMidLayer17;'MidLayer18':      Result := eMidLayer18;'MidLayer19':      Result := eMidLayer19;'MidLayer20':      Result := eMidLayer20;'MidLayer21':      Result := eMidLayer21;'MidLayer22':      Result := eMidLayer22;'MidLayer23':      Result := eMidLayer23;'MidLayer24':      Result := eMidLayer24;'MidLayer25':      Result := eMidLayer25;'MidLayer26':      Result := eMidLayer26;'MidLayer27':      Result := eMidLayer27;'MidLayer28':      Result := eMidLayer28;'MidLayer29':      Result := eMidLayer29;'MidLayer30':      Result := eMidLayer30;'BottomLayer':     Result := eBottomLayer;'TopOverlay':      Result := eTopOverlay;'BottomOverlay':   Result := eBottomOverlay;'TopPaste':        Result := eTopPaste;'BottomPaste':     Result := eBottomPaste;'TopSolder':       Result := eTopSolder;'BottomSolder':    Result := eBottomSolder;'InternalPlane1':  Result := eInternalPlane1;'InternalPlane2':  Result := eInternalPlane2;'InternalPlane3':  Result := eInternalPlane3;'InternalPlane4':  Result := eInternalPlane4;'InternalPlane5':  Result := eInternalPlane5;'InternalPlane6':  Result := eInternalPlane6;'InternalPlane7':  Result := eInternalPlane7;'InternalPlane8':  Result := eInternalPlane8;'InternalPlane9':  Result := eInternalPlane9;'InternalPlane10': Result := eInternalPlane10;'InternalPlane11': Result := eInternalPlane11;'InternalPlane12': Result := eInternalPlane12;'InternalPlane13': Result := eInternalPlane13;'InternalPlane14': Result := eInternalPlane14;'InternalPlane15': Result := eInternalPlane15;'InternalPlane16': Result := eInternalPlane16;'DrillGuide':      Result := eDrillGuide;'KeepOutLayer':    Result := eKeepOutLayer;'Mechanical1':     Result := eMechanical1;'Mechanical2':     Result := eMechanical2;'Mechanical3':     Result := eMechanical3;'Mechanical4':     Result := eMechanical4;'Mechanical5':     Result := eMechanical5;'Mechanical6':     Result := eMechanical6;'Mechanical7':     Result := eMechanical7;'Mechanical8':     Result := eMechanical8;'Mechanical9':     Result := eMechanical9;'Mechanical10':    Result := eMechanical10;'Mechanical11':    Result := eMechanical11;'Mechanical12':    Result := eMechanical12;'Mechanical13':    Result := eMechanical13;'Mechanical14':    Result := eMechanical14;'Mechanical15':    Result := eMechanical15;'Mechanical16':    Result := eMechanical16;'DrillDrawing':    Result := eDrillDrawing;'MultiLayer':      Result := eMultiLayer;'ConnectLayer':    Result := eConnectLayer;'BackGroundLayer': Result := eBackGroundLayer;'DRCErrorLayer':   Result := eDRCErrorLayer;'HighlightLayer':  Result := eHighlightLayer;'GridColor1':      Result := eGridColor1;'GridColor10':     Result := eGridColor10;'PadHoleLayer':    Result := ePadHoleLayer;'ViaHoleLayer':    Result := eViaHoleLayer;ElseResult := eNoLayer;End;
End;Procedure FP_AddStep(fp: IPCB_LibComponent, Data: String, InFileName: String);
VarSTEPFileName   : String;STEPmodel      : IPCB_ComponentBody;Model          : IPCB_Model;
Begin//STEPFileName := GetFileLocation(InFileName) + '\' + GetBetween(Data, '(Name ', ')');//通过修改上面这行中的分隔符,同时在执行过程中屏蔽   Model := STEPmodel.ModelFactory_FromFilename(STEPFileName, false);    再打开这行 就可生成封装库STEPFileName := GetFileLocation(InFileName) + GetBetween(Data, '(Name ', ')');STEPmodel := PcbServer.PCBObjectFactory(eComponentBodyObject,eNoDimension,eCreate_Default);//Model := STEPmodel.ModelFactory_FromFilename(STEPFileName, false);Model := STEPmodel.ModelFactory_FromFilename(STEPFileName, false);STEPmodel.SetState_FromModel;//   Model.SetState(0,0,0,0);STEPmodel.Model := Model;fp.AddPCBObject(STEPmodel);//PCBServer.SendMessageToRobots(fp.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, arc.I_ObjectAddress);
End;Procedure FP_AddLine(fp: IPCB_Component, Data: String);
Varlin : IPCB_track;s1, s2 : String;
Beginlin := PCBServer.PCBObjectFactory(eTrackObject, eNoDimension, eCreate_Default);If lin = Nil Then Exit;StrChop(GetBetween(Data, '(Start ', ')'), ',', s1, s2);lin.X1 := MilsToCoord(Evaluate(s1));lin.Y1 := MilsToCoord(Evaluate(s2));StrChop(GetBetween(Data, '(End ', ')'), ',', s1, s2);lin.X2 := MilsToCoord(Evaluate(s1));lin.Y2 := MilsToCoord(Evaluate(s2));lin.Layer := LayerFromString(GetBetween(Data, '(Layer ', ')'));lin.Width := MilsToCoord(Evaluate(GetBetween(Data, '(Width ', ')')));fp.AddPCBObject(lin);PCBServer.SendMessageToRobots(fp.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, lin.I_ObjectAddress);
End;Procedure FP_AddArc(fp: IPCB_Component, Data: String);
Vararc : IPCB_Arc;s1, s2 : String;
Beginarc := PCBServer.PCBObjectFactory(eArcObject, eNoDimension, eCreate_Default);If arc = Nil Then Exit;StrChop(GetBetween(Data, '(Location ', ')'), ',', s1, s2);arc.XCenter := MilsToCoord(Evaluate(s1));arc.YCenter := MilsToCoord(Evaluate(s2));arc.Radius := MilsToCoord(Evaluate(GetBetween(Data, '(Radius ', ')')));arc.LineWidth := MilsToCoord(Evaluate(GetBetween(Data, '(Width ', ')')));arc.StartAngle := Evaluate(GetBetween(Data, '(StartAngle ', ')'));arc.EndAngle := Evaluate(GetBetween(Data, '(EndAngle ', ')'));arc.Layer := LayerFromString(GetBetween(Data, '(Layer ', ')'));;fp.AddPCBObject(arc);PCBServer.SendMessageToRobots(fp.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, arc.I_ObjectAddress);
End;Procedure FP_AddPoly(fp: IPCB_Component, Data: String, InFile: TextFile);
Varpol : IPCB_Region;cont : IPCB_Contour;pc: Integer;s1, s2, inp, tag : String;
Beginpol := PCBServer.PCBObjectFactory(eRegionObject, eNoDimension,eCreate_Default);If pol = Nil Then Exit;cont := pol.MainContour.Replicate();pol.Layer := LayerFromString(GetBetween(Data, '(Layer ', ')'));cont.Count := Evaluate(GetBetween(Data, '(PointCount ', ')'));pc := 0;While Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;inp := Trim(inp);StrChop(inp, ' ', tag, inp);tag := Trim(tag);Case tag Of'Point': Beginpc := pc + 1;StrChop(GetBetween(inp, '(', ')'), ',', s1, s2);cont.X[pc] := MilsToCoord(Evaluate(s1));cont.Y[pc] := MilsToCoord(Evaluate(s2));End;'EndPolygon': Break;Else BeginShowMessage('Keyword Error: ' + tag);End;End;End;pol.SetOutlineContour(cont);If GetBetween(Data, '(Type ', ')') = 'KeepOut' Then Beginpol.IsKeepout := True;End;fp.AddPCBObject(pol);PCBServer.SendMessageToRobots(fp.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, pol.I_ObjectAddress);
End;Procedure FP_AddText(fp: IPCB_Component, Data: STring);
Vartxt : IPCB_Text;s1, s2 : String;
Begintxt := PCBServer.PCBObjectFactory(eTextObject, eNoDimension, eCreate_Default);If txt = Nil Then Exit;StrChop(GetBetween(Data, '(Location ', ')'), ',', s1, s2);txt.XLocation := MilsToCoord(Evaluate(s1));txt.YLocation := MilsToCoord(Evaluate(s2));txt.Layer := LayerFromString(GetBetween(Data, '(Layer ', ')'));txt.Size := MilsToCoord(Evaluate(GetBetween(Data, '(Height ', ')')));txt.Width := MilsToCoord(Evaluate(GetBetween(Data, '(Width ', ')')));If GetBetween(Data, '(Mirrored ', ')') = 'True' Then Begintxt.MirrorFlag := True;End;txt.Rotation := Evaluate(GetBetween(Data, '(Rotation ', ')'));txt.Text := GetBetween(Data, '(Value "', '")');// Justification? NOTE: TODO:fp.AddPCBObject(txt);PCBServer.SendMessageToRobots(fp.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, txt.I_ObjectAddress);
End;Procedure FP_AddPad(fp: IPCB_Component, Data: String, InFile: TextFile);
Vars1, s2, inp, tag, lay : String;pad : IPCB_Pad;padsh : TShape;cache : TPadCache;
Beginpad := PcbServer.PCBObjectFactory(ePadObject, eNoDimension, eCreate_Default);pad.Name := GetBetween(Data, '(Name "', '")');
//    pad.Layer := LayerFromString(GetBetween(Data, '(Layer ', ')'));StrChop(GetBetween(Data, '(Location ', ')'), ',', s1, s2);pad.X := MilsToCoord(Evaluate(s1));pad.Y := MilsToCoord(Evaluate(s2));pad.Rotation := Evaluate(GetBetween(Data, '(Rotation ', ')')); // 2010-07-06 gbn
//    pad.Mode := ePadMode_LocalStack; // ePadMode_Simple, ePadMode_ExternalStacks1 := GetBetween(Data, '(ExpandPaste ', ')');s2 := GetBetween(Data, '(ExpandMask ', ')');If s1 <> '' || s2 <> '' Then Begincache := pad.Cache;If s1 <> '' Then Begincache.PasteMaskExpansionValid := eCacheManual;cache.PasteMaskExpansion := MilsToCoord(Evaluate(s1));End;If s2 <> '' Then Begincache.SolderMaskExpansionValid := eCacheManual;cache.SolderMaskExpansion := MilsToCoord(Evaluate(s2));End;pad.Cache := cache;End;If GetBetween(Data, '(Surface ', ')') = 'True' Then Beginpad.Mode := ePadMode_Simple;pad.Layer := eTopLayer;End Else Beginpad.Mode := ePadMode_LocalStack;End;pad.HoleType := eRoundHole; // eSquareHole, eSlotHolepad.HoleSize := MilsToCoord(Evaluate(GetBetween(Data, '(HoleSize ', ')')));While Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;inp := Trim(inp);StrChop(inp, ' ', tag, inp);tag := Trim(tag);Case tag Of'PadShape': Beginpadsh := eNoShape;StrChop(GetBetween(inp, '(Size ', ')'), ',', s1, s2);Case GetBetween(inp, '(Shape ', ')') Of'NoShape': padsh := eNoShape;'Rounded': padsh := eRounded;'Rectangular': padsh := eRectangular;'Octagonal': padsh := eOctagonal;'CircleShape': padsh := eCircleShape;'ArcShape': padsh := eArcShape;'Terminator': padsh := eTerminator;'RoundedRectangle': padsh := eRoundedRectangular;'RotatedRectangle': padsh := eRotatedRectShape;Else padsh := eNoShape;End;lay := GetBetween(inp, '(Layer ', ')');If CheckLeft(lay, 'Top') Then Beginpad.TopShape := padsh;pad.TopXSize := MilsToCoord(Evaluate(s1));pad.TopYSize := MilsToCoord(Evaluate(s2));End Else If CheckLeft(lay, 'Mid') Then Beginpad.MidShape := padsh;pad.MidXSize := MilsToCoord(Evaluate(s1));pad.MidYSize := MilsToCoord(Evaluate(s2));End Else If CheckLeft(lay, 'Bot') Then Beginpad.BotShape := padsh;pad.BotXSize := MilsToCoord(Evaluate(s1));pad.BotYSize := MilsToCoord(Evaluate(s2));End;End;'EndPad': BeginBreak;End;Else BeginShowMessage('Keyword Error: ' + tag);End;End;End;fp.AddPCBObject(pad);PCBServer.SendMessageToRobots(fp.I_ObjectAddress, c_Broadcast, PCBM_BoardRegisteration, pad.I_ObjectAddress);
End;Procedure ImportFootprints(InFile: TextFile, Lib: IPCB_Library, Errors: TStringList, InFileName : String);
Varinp, tag, s, t : String;fp : IPCB_Component;
BeginWhile Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;inp := Trim(inp);StrChop(inp, ' ', tag, inp);tag := Trim(tag);Case tag Of'Footprint': Begin// create a footprint referencefp := PCBServer.CreatePCBLibComp();If fp = Nil Then BeginErrors.Add('Error creating footprint.');Break;End;// add data to itfp.Name := GetBetween(inp, '(Name "', '")');// assign it to libraryLib.RegisterComponent(fp);PCBServer.PreProcess();// add data to itfp.BeginModify();// set heightt := GetBetween(inp, '(Height ', ')');If t <> '' Then Beginfp.Height := MilsToCoord(Evaluate(t));End;While Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;inp := Trim(inp);If CheckLeft(inp, '#') Then Continue;StrChop(inp, ' ', tag, inp);tag := Trim(tag);Case tag Of'Pad': BeginFP_AddPad(fp, inp, InFile);End;'Line': BeginFP_AddLine(fp, inp);End;'Arc': BeginFP_AddArc(fp, inp);End;'Polygon': BeginFP_AddPoly(fp, inp, InFile);End;'Text': BeginFP_AddText(fp, inp);End;'Step': BeginFP_AddStep(fp, inp, InFileName);End;'EndFootprint': Begin//ShowMessage('EndFootprint');Break;End;'': Continue;Else BeginShowMessage('Keyword Error: ' + tag);Break;End;End;End; // while not eof()fp.EndModify();PCBServer.PostProcess();// done with footprintEnd;'EndFootprints': Begin//ShowMessage('EndFootprint');Break;End;'': Continue;Else BeginShowMessage('Keyword Error: ' + tag);Break;End;End; // case tagEnd; // while not eof()PCBServer.PostProcess();
End;{==============================================================================}
{====  Symbol Routines  =======================================================}
{==============================================================================}Function TextJustificationFromString(Value: String): TTextJustification;
BeginCase Value Of'BottomLeft':   Result := eJustify_BottomLeft;'BottomCenter': Result := eJustify_BottomCenter;'BottomRight': Result := eJustify_BottomRight;'CenterLeft': Result := eJustify_CenterLeft;'Center': Result := eJustify_Center;'CenterRight': Result := eJustify_CenterRight;'TopLeft': Result := eJustify_TopLeft;'TopCenter': Result := eJustify_TopCenter;'TopRight': Result := eJustify_TopRight;Else Result := eJustify_Center;End;
End;Function SY_GetFont(Height: Double, Angle: TRotationBy90): TFontID;
Varsz : Integer;
Begin// 2012-11-07 gbn start{ sz := Round(Height / 10);According to this page's bugs 4604 and 5552, Altium 10.890.23450 may have this fixed.http://wiki.altium.com/pages/viewpage.action?pageId=34210039}sz := (Height * 0.1);// 2012-11-07 gbn endResult := SchServer.FontManager.GetFontID(sz, Angle, False, False, False, False, 'Courier New');
End;Function SY_GetAngle(Angle : String): TRotationBy90;
BeginCase Angle Of'90': Result := eRotate90;'180': Result := eRotate180;'270': Result := eRotate270;Else Result := eRotate0;End;
End;Procedure SY_AddLine(sy: ISch_Component, Data: String);
Varlin : ISch_Line;s1, s2 ,s3: String;
Beginlin := SchServer.SchObjectFactory(eLine, eCreate_Default);If lin = Nil Then Exit;StrChop(GetBetween(Data, '(Start ', ')'), ',', s1, s2);lin.Location := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));StrChop(GetBetween(Data, '(End ', ')'), ',', s1, s2);lin.Corner := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));GetBetween(Data, 'Width ', ')');If s3 < 10 Then Beginlin.LineWidth := eSmall;End;If s3 > 10 Then Beginlin.LineWidth := eMedium;End;If s3 > 12 Then Beginlin.LineWidth := eLarge;End;lin.LineStyle := eLineStyleSolid;lin.Color := $000000; // NOTE: TODO:lin.OwnerPartId := Evaluate(GetBetween(Data, '(Part ', ')'));lin.OwnerPartDisplayMode := sy.DisplayMode;sy.AddSchObject(lin);SchServer.RobotManager.SendMessage(sy.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, lin.I_ObjectAddress);
End;Procedure SY_AddRect(sy: ISch_Component, Data: String);
Varrect : ISch_Rectangle;s1, s2 ,s3: String;
Beginrect := SchServer.SchObjectFactory(eRectangle, eCreate_Default);If rect = Nil Then Exit;StrChop(GetBetween(Data, '(Start ', ')'), ',', s1, s2);rect.Location := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));StrChop(GetBetween(Data, '(End ', ')'), ',', s1, s2);rect.Corner := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));GetBetween(Data, 'Width ', ')');s3 := GetBetween(Data, '(Width ', ')');If s3 < 10 Then Beginrect.LineWidth := eSmall;End;If s3 > 10 Then Beginrect.LineWidth := eMedium;End;If s3 > 12 Then Beginrect.LineWidth := eLarge;End;rect.Transparent := True;rect.Color := $000000; // NOTE: TODO:rect.OwnerPartId := Evaluate(GetBetween(Data, '(Part ', ')'));rect.OwnerPartDisplayMode := sy.DisplayMode;sy.AddSchObject(rect);SchServer.RobotManager.SendMessage(sy.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, rect.I_ObjectAddress);
End;Procedure SY_AddArc(sy: ISch_Component, Data: String);
Vararc : ISch_Arc;s1, s2, s3 : String;
Beginarc := SchServer.SchObjectFactory(eArc, eCreate_Default);If arc = Nil Then Exit;StrChop(GetBetween(Data, '(Location ', ')'), ',', s1, s2);arc.Location := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));arc.Radius := MilsToCoord(Evaluate(GetBetween(Data, '(Radius ', ')')));s3 := GetBetween(Data, '(Width ', ')');If s3 < 10 Then Beginarc.LineWidth := eSmall;End;If s3 > 10 Then Beginarc.LineWidth := eMedium;End;If s3 > 12 Then Beginarc.LineWidth := eLarge;End;arc.Color := $000000; // NOTE: TODO:arc.StartAngle := Evaluate(GetBetween(Data, '(StartAngle ', ')'));arc.EndAngle := Evaluate(GetBetween(Data, '(EndAngle ', ')'));arc.OwnerPartId := Evaluate(GetBetween(Data, '(Part ', ')'));arc.OwnerPartDisplayMode := sy.DisplayMode;sy.AddSchObject(arc);SchServer.RobotManager.SendMessage(sy.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, arc.I_ObjectAddress);
End;Procedure SY_AddPoly(sy: ISch_Component, Data: String, InFile: TextFile);
Varpol : ISch_Polygon;pc: Integer;s1, s2, inp, tag : String;
Beginpol := SchServer.SchObjectFactory(ePolygon, eCreate_Default);If pol = Nil Then Exit;pol.VerticesCount := Evaluate(GetBetween(Data, '(PointCount ', ')'));pc := 0;While Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;inp := Trim(inp);StrChop(inp, ' ', tag, inp);tag := Trim(tag);Case tag Of'Point': Beginpc := pc + 1;StrChop(GetBetween(inp, '(', ')'), ',', s1, s2);pol.Vertex[pc] := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));End;'EndPolygon': Break;Else BeginShowMessage('Keyword Error: ' + tag);End;End;End;pol.LineWidth := eZeroSize; // NOTE: TODO:pol.Color := $000000; // NOTE: TODO:pol.IsSolid := True;pol.OwnerPartId := Evaluate(GetBetween(Data, '(Part ', ')'));pol.OwnerPartDisplayMode := sy.DisplayMode;sy.AddSchObject(pol);SchServer.RobotManager.SendMessage(sy.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, pol.I_ObjectAddress);
End;Procedure SY_AddText(sy: ISch_Component, Data: String);
Vartxt : ISch_Label;s1, s2 : String;
Begintxt := SchServer.SchObjectFactory(eLabel, eCreate_Default);If txt = Nil Then Exit;StrChop(GetBetween(Data, '(Location ', ')'), ',', s1, s2);txt.Location := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));If GetBetween(Data, '(Mirrored ', ')') = 'True' Then Begintxt.IsMirrored := True;End;txt.Orientation := SY_GetAngle(GetBetween(Data, '(Rotation ', ')'));txt.FontID := SY_GetFont(Evaluate(GetBetween(Data, 'Height ', ')')), txt.Orientation);txt.Justification := TextJustificationFromString(GetBetween(Data, '(Justification ', ')'));txt.Color := $000000; // NOTE: TODO:txt.Text := GetBetween(Data, '(Value "', '")');txt.OwnerPartId := Evaluate(GetBetween(Data, '(Part ', ')'));txt.OwnerPartDisplayMode := sy.DisplayMode;sy.AddSchObject(txt);SchServer.RobotManager.SendMessage(sy.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, txt.I_ObjectAddress);
End;Procedure SY_AddParam(sy: ISch_Component, Data: String);
Varprm : ISch_Parameter;s1, s2: String;
Beginprm := SchServer.SchObjectFactory(eParameter, eCreate_Default);If prm = Nil Then Exit;prm.IsHidden := True;If GetBetween(Data, '(Name ', '"') = 'Visible' Then Beginprm.IsHidden := False;End;prm.Name := GetBetween(Data, '(Name "', '")');StrChop(GetBetween(Data, '(Location ', ')'), ',', s1, s2);prm.Location := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));If GetBetween(Data, '(Mirrored ', ')') = 'True' Then Beginprm.IsMirrored := True;End;prm.Orientation := SY_GetAngle(GetBetween(Data, '(Rotation ', ')'));prm.FontID := SY_GetFont(Evaluate(GetBetween(Data, 'Height ', ')')), prm.Orientation);prm.Justification := TextJustificationFromString(GetBetween(Data, '(Justification ', ')'));prm.Color := $000000; // NOTE: TODO:prm.Text := GetBetween(Data, '(Value "', '")');prm.OwnerPartId := Evaluate(GetBetween(Data, '(Part ', ')'));prm.OwnerPartDisplayMode := sy.DisplayMode;sy.AddSchObject(prm);SchServer.RobotManager.SendMessage(sy.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, prm.I_ObjectAddress);
End;Procedure SY_AddPin(sy: ISch_Component, Data: String);
Varpin : ISch_Pin;s1, s2 : String;
Beginpin := SchServer.SchObjectFactory(ePin, eCreate_Default);If pin = Nil Then Exit;// Define the pin parameters.StrChop(GetBetween(Data, '(Location ', ')'), ',', s1, s2);pin.Location := Point(MilsToCoord(Evaluate(s1)), MilsToCoord(Evaluate(s2)));pin.Color := $000000; // NOTE: TODO:pin.Orientation := SY_GetAngle(GetBetween(Data, '(Rotation ', ')'));Case GetBetween(Data, '(PinType ', ')') Of'IO': pin.Electrical := eElectricIO;'Input': pin.Electrical := eElectricInput;'Output': pin.Electrical := eElectricOutput;'Passive': pin.Electrical := eElectricPassive;'OpenCollector': pin.Electrical := eElectricOpenCollector;'OpenEmitter': pin.Electrical := eElectricOpenEmitter;'HiZ': pin.Electrical := eElectricHiZ;'Power': pin.Electrical := eElectricPower;Else pin.Electrical := eElectricPassive;End;pin.PinLength := MilsToCoord(Evaluate(GetBetween(Data, '(Length ', ')')));pin.SwapId_Pin :=  GetBetween(Data, '(PinSwap ', ')');pin.SwapId_Part := GetBetween(Data, '(PartSwap ', ')');pin.SwapId_PartPin := GetBetween(Data, '(PinSeq ', ')');s1 := GetBetween(Data, '(Designator ', '")');pin.ShowDesignator := CheckLeft(s1, 'Visible');pin.Designator := RightOf(s1, '"');s1 := GetBetween(Data, '(Name ', '")');pin.ShowName := CheckLeft(s1, 'Visible');pin.Name := RightOf(s1, '"');pin.OwnerPartId := Evaluate(GetBetween(Data, '(Part ', ')'));pin.OwnerPartDisplayMode := sy.DisplayMode;sy.AddSchObject(pin);SchServer.RobotManager.SendMessage(sy.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, pin.I_ObjectAddress);
End;Procedure ImportComponents(InFile: TextFile, Lib: ISch_Document, Errors: TStringList);
Varinp, tag, s, t : String;sy : ISch_Component;simp : ISch_Implementation;
BeginWhile Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;StrChop(inp, ' ', tag, inp);tag := Trim(tag);Case tag Of'Component': Begin// create a component referencesy := SchServer.SchObjectFactory(eSchComponent, eCreate_Default);If sy = Nil Then BeginErrors.Add('Error creating component.');Break;End;// Set up parameters for the library component.SchServer.ProcessControl.PreProcess(Lib, '');// Define the LibReference and add the component to the library.sy.LibReference := GetBetween(inp, '(Name "', '")');sy.Designator.Text := GetBetween(inp, '(DesPrefix "', '")');sy.ComponentDescription := 'Imported';sy.PartCount := Evaluate(GetBetween(inp, '(PartCount ', ')'));sy.CurrentPartId := 1;// add data to itWhile Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;StrChop(inp, ' ', tag, inp);Case tag Of'Parameter': BeginSY_AddParam(sy, inp);End;'Pin': BeginSY_AddPin(sy, inp);End;'Line': BeginSY_AddLine(sy, inp);End;'Rectangle': BeginSY_AddRect(sy, inp);End;'Arc': BeginSY_AddArc(sy, inp);End;'Polygon': BeginSY_AddPoly(sy, inp, InFile);End;'Text': BeginSY_AddText(sy, inp);End;'Footprint': Beginsimp := sy.AddSchImplementation();simp.ModelName := GetBetween(inp, '(Name "', '")');simp.ModelType := cDocKind_PcbLib;simp.AddDataFileLink(simp.ModelName, '', cDocKind_PcbLib);simp.MapAsString := GetBetween(inp, '(Map "', '")');End;'EndComponent': BeginLib.AddSchComponent(sy);// Send a system notification that a new component has been added to the library.SchServer.RobotManager.SendMessage(Lib.I_ObjectAddress, c_BroadCast, SCHM_PrimitiveRegistration, sy.I_ObjectAddress);Lib.CurrentSchComponent := sy;Break;End;'': Continue;Else BeginShowMessage('Keyword Error: ' + tag);Break;End;End;End; // while not eof()// done with componentSchServer.ProcessControl.PostProcess(Lib, '');End;'EndComponents': BeginBreak;End;'': Continue;Else BeginShowMessage('Keyword Error: ' + tag);Break;End;End; // case tagEnd; // while not eof()
End;{==============================================================================}
{====  Main Routines  =========================================================}
{==============================================================================}Function InitLibDocs(BasePath: String,Out Proj : IProject,Out ProjDoc : IServerDocument,Out PcbLibDoc : IServerDocument,Out SchLibDoc : IServerDocument,Out pLib : IPCB_Library,Out sLib : ISch_Document): Boolean;
VarWorkSpace : IWorkSpace;
BeginResult := False;WorkSpace := GetWorkSpace;If WorkSpace = Nil Then BeginShowMessage('Nil WorkSpace');Exit;End;// Integrated library, and the project it createsProjDoc := Client.OpenNewDocument(cDocKind_IntegratedLibrary, 'UL_Imported_Lib', 'UL_Imported_Lib', False);If ProjDoc = Nil Then BeginShowMessage('Nil ProjDoc');Exit;End;If Not ProjDoc.DoSafeChangeFileNameAndSave(BasePath + '.LibPkg', cDocKind_IntegratedLibrary) Then BeginShowMessage('ProjDoc Save failed');Exit;End;Proj := WorkSpace.DM_GetProjectFromPath(BasePath + '.LibPkg');If Proj = Nil Then BeginShowMessage('Nil Proj');Exit;End;// Footprint libraryPcbLibDoc := Client.OpenNewDocument(cDocKind_PcbLib, 'UL_Footprints', 'UL_Footprints', False);If PcbLibDoc = Nil Then BeginShowMessage('Nil PcbLibDoc');Exit;End;If Not PcbLibDoc.DoSafeChangeFileNameAndSave(BasePath + '.PcbLib', cDocKind_PcbLib) Then BeginShowMessage('PcbLibDoc Save failed');Exit;End;Proj.DM_AddSourceDocument(BasePath + '.PcbLib');pLib := PCBServer.GetPCBLibraryByPath(BasePath + '.PcbLib');If pLib = Nil Then BeginShowMessage('Nil pLib');Exit;End;// Symbol LibrarySchLibDoc := Client.OpenNewDocument(cDocKind_SchLib, 'UL_Components', 'UL_Components', False);If SchLibDoc = Nil Then BeginShowMessage('Nil SchLibDoc');Exit;End;If Not SchLibDoc.DoSafeChangeFileNameAndSave(BasePath + '.SchLib', cDocKind_SchLib) Then BeginShowMessage('SchLibDoc Save failed');Exit;End;Proj.DM_AddSourceDocument(BasePath + '.SchLib');sLib := SchServer.GetSchDocumentByPath(BasePath + '.SchLib');If sLib = Nil Then BeginShowMessage('Nil sLib');Exit;End;// DoneResult := True;
End;Procedure ImportAscIIData(InFileName : String);
VarWorkSpace : IWorkSpace;dProj : IProject;Proj : IProject;ProjDoc : IServerDocument;PcbLibDoc : IServerDocument;SchLibDoc : IServerDocument;pLib : IPCB_Library;sLib : ISch_Document;DefFP : IPCB_Component; // default initial blank footprintDefSY : ISch_Component; // default initial blank symbolSavePath: String;InFile : TextFile;Errors : TStringList;inp, tag : String;
BeginSavePath := LeftOf(InFileName, '.');Errors := TStringList.Create();WorkSpace := GetWorkSpace;If WorkSpace = Nil Then BeginShowMessage('Nil WorkSpace');Exit;End;dProj := WorkSpace.DM_FocusedProject();// create integerated library documentsIf InitLibDocs(SavePath, Proj, ProjDoc, PcbLibDoc, SchLibDoc, pLib, sLib) = False Then BeginShowMessage('Error initializing library');Exit;End;Proj.DM_SetAsCurrentProject();// get the original blank footprint for later deletion when we are doneDefFP := pLib.CurrentComponent;// get the original blank symbol for later deletion when we are doneDefSy := sLib.CurrentSchComponent;// start importing dataAssignFile(InFile, InFileName);Reset(InFile);While Not EOF(InFile) Do BeginReadLn(InFile, inp);If VarIsNull(inp) Then Continue;StrChop(inp, ' ', tag, inp);tag := Trim(tag);Case tag Of'StartFootprints': BeginImportFootprints(InFile, pLib, Errors, InFileName);End;'StartComponents': BeginImportComponents(InFile, sLib, Errors);End;'': Continue;End;End;CloseFile(InFile);// delete the original default blank footprintIf Not VarIsNull(DefFP) Then BeginpLib.DeRegisterComponent(DefFP);pLib.RemoveComponent(DefFP);End Else BeginShowMessage('DefFP was Nil');End;// delete the original default blank symbol// NOTE: TODO: looks broken; does nothing noticableIf Not VarIsNull(DefSY) Then Begin//ShowMessage('trying to delete DefSym "' + DefSy.LibReference + '"');sLib.UnRegisterSchObjectFromContainer(DefSY);sLib.RemoveSchObject(DefSy);//DefSY.Container.RemoveSchObject(DefSy);End Else BeginShowMessage('DefSym was Nil');End;// update views?pLib.Board.ViewManager_FullUpdate();// Refresh symbol library.sLib.GraphicallyInvalidate();// save files againProjDoc.DoFileSave(cDocKind_IntegratedLibrary);PcbLibDoc.DoFileSave(cDocKind_PcbLib);SchLibDoc.DoFileSave(cDocKind_SchLib);// set the original project back to its focusIf dProj <> Nil Then BegindProj.DM_SetAsCurrentProject();End;ShowMessage('Done with "' + SavePath + '"');
End;

.bxl文件导入Altium Designer的方法,及错误解决相关推荐

  1. MLT教程:从BXL文件导入Altium Designer原理图封装和PCB封装

    在TI官网的封装文件中提供弄BXL文件可以导出Altium Designer的封装库和原理图库. 这个界面往下面拉会看到: 然后可以下载各种封装的bxl文件了.下面视频说明bxl文件如何导出成功. 如 ...

  2. Altium Designer使用方法(DRC警告设置,走线技巧,DIY电路板打印技术)

    装载于: https://www.amobbs.com/thread-4156706-1-1.html Altium Designer使用方法,看到大家对DRC乱设置,还是给大家做一些视频吧,我不用p ...

  3. 将DBF,XLS,XML,MDB文件导入C#DataGrid的方法

    以下的源码里分别给出了将DBF,XLS,XML,MDB文件导入C#DataGrid的方法,供各位参考. //PutInDataSet.cs的源码 using System; using System. ...

  4. Altium Designer出现advpcb.all错误的解决方法

    Altium Designer出现advpcb.dll错误的解决方法 报错的原图是这样的,我发现在查看PCB3D封装的时候就会出现,在2D的情况下正常,网上有人说是其他版本的文件有残留,于是我在d盘和 ...

  5. HFSS天线仿真文件到Altium Designer绘制PCB

    HFSS天线仿真文件到Altium Designer绘制PCB 概述 1.HFSS导出DXF文件 2.DXF文件导入AD并进行PCB绘制 概述 本文主要记录一下如何用Altium Designer进行 ...

  6. csv导入mysql php实现_PHP实现csv文件导入mysql数据库的方法

    这篇文章主要介绍了PHP编程实现csv文件导入mysql数据库的方法,涉及php文件读取.转换.数据库的连接.插入等相关操作技巧,需要的朋友可以参考下 具体如下: config.db.php内容如下: ...

  7. Altium Designer 19卡顿的解决方法

    Altium Designer 19卡顿的解决方法 参考文章: (1)Altium Designer 19卡顿的解决方法 (2)https://www.cnblogs.com/Si-Mao/p/122 ...

  8. 使用AndroidStudio编译NDK的方法及错误解决方式

    使用AndroidStudio编译NDK的方法及错误解决方式 参考文章: (1)使用AndroidStudio编译NDK的方法及错误解决方式 (2)https://www.cnblogs.com/me ...

  9. webpack 4.0 配置方法以及错误解决

    webpack 4.0 配置方法以及错误解决 参考文章: (1)webpack 4.0 配置方法以及错误解决 (2)https://www.cnblogs.com/qqfontofweb/p/8516 ...

最新文章

  1. html canvas 与小丑 。
  2. Java applet java.lang.OutOfMemoryError: Java heap space
  3. python pickle反序列化漏洞_Python Pickle反序列化带来的安全问题
  4. 重磅 | Dragonfly 晋升成为 CNCF 孵化项目
  5. 定积分算法java_变步长梯形积分算法求解函数定积分
  6. Java 蓝桥杯 数列特征
  7. 25. (附加)二叉树的所有路径(C++版本)
  8. 计算机主机技术标准规范,数据中心机房建设,需要依据哪些国家标准和行业标准或规范?...
  9. (译)如何使用spritehelper和levelhelper教程:引子
  10. PDF文件怎么转换成Excel表格?学会这个方法轻松转换。
  11. android 远程桌面软件,安卓上的远程桌面软件:Xtralogic Remote Desktop Client
  12. Php将mp3转wav,mp3转wav格式转换器 mp3怎么转换成wav格式
  13. 狮子座与摩羯座 ---转载
  14. eclipse查看安装了哪些插件
  15. H5页面、微页、轻应用、轻app、场景应用制作工具:
  16. PTA程序设计天梯赛 L2题解报告(40/40)
  17. 2022-2028全球食品级柠檬酸镁行业调研及趋势分析报告
  18. 13c语言——运算符
  19. 公司测试部门来了个00后卷王,老油条感叹真干不过,不过.....
  20. 竞价推广关键词怎么选择?

热门文章

  1. 弹性均质圆环法计算过程_同济大学地下建筑结构复习要点
  2. C#/VB.NET 自定义PPT动画路径
  3. a4纸对折c语言,一张A4纸最多可对折几次,这个实验太好玩了
  4. AD学习问题记录(四):AD21布线时如何更改线宽
  5. 资本资产定价模型简介-多因子寻找Alpha统计套利
  6. Breed Counting(水?)
  7. 数据分析如何避免客户流失
  8. Java模拟微信抢红包
  9. java毕业生设计学校医院预约系统计算机源码+系统+mysql+调试部署+lw
  10. 使用ULIB+Altium Designer绘制元件原理图及封装