CST_2010_VBA_宏

  • 格式:doc
  • 大小:151.00 KB
  • 文档页数:28

' *Construct / Discrete Ports / Compute SelfInductance of Dis.Ports' !!! Do not change the line above !!'' fhi: 12-07-2010 check angle and size of two parent ports, option dCaps instead of Ports' fhi: 09-07-2010 added neg. mutual couplings' fhi: 25-05-2010 Distinguish between !T and !F for Hex-Mesh: Hexmesh !F does not consider face-ports.' fhi: 24-02-2010 inactivated WG Port connections for the moment (multi-pin, multi-Mode not supported)' fhi: 20-01-2010 added Face-port capability for L and C computation, tet and hex mesh, (tet-face-port new formulation in 2010)' fhi: 21-10-2009 Port.GetFacePortSize( pnr, b_dir1, l_dir2 )' fhi: 05-03-2009 added links to Caps for differential/nondifferential Links' fhi: 10-09-2007 Caps on/off, mesh symmetry-planes considered , mesh-search based on min/max mesh-step' fhi: 20-08-2007 adapted to DE2008' fhi: 03-04-2006 Compute -L for arbitrarily orientated ports and adds them into DesignStudio' fhi: 05-04-2006 De2006: SP5 corrections: PR Tracker 2593, 2608 - 2610, 2614' fhi: 07-04-2006 Differential_ports and Blocks implemented, Dialog added, autom. deletion of existing ports/blocks' fhi: 30-10-2006 Correction of z_lower=Mesh.getzpos(Z_istop) in subroutine "search_for_zlower_z_upper"' fhi: 31-10-2006 Added equivalent capacitance of ports (port-wires rep. by two long cylinders)' fhi: 11-02-2006 Initial versionOption ExplicitPublic ListPortArray() As StringPublic PortArrayLength As IntegerPublic Discrete_Port_List() As String, Total_Nr_of_Discrete_Ports As Integer, N_max_searches As IntegerSub MainDim long_ref_dir As Long, long_ref_index As Long, port_nr As Integer, delta As DoubleDim x As Double, y As Double, z As Double, plength As Double, X_start_index As Long, X_istop As LongDim x_upper As Double, x_lower As Double, wire_radius As DoubleDim Y_start_index As Long, Y_istop As Long, y_upper As Double, y_lower As Double, L_i As Double Dim L_a As Double, glength As Double, iii As Integer, port_name As String, index_p As Long, index_q As LongDim port_index As Long, z_upper As Double, z_lower As Double, output_string As StringDim long_ref_index2 As Long, source_start_point As Double, source_end_point As DoubleDim source_length As Double, port_onearmlength As Double, C_port As DoubleDoubleDim K_array() As Double, L_array () As Double, M As Double, k As DoubleDim x0_p As Double, y0_p As Double, z0_p As Double, glength1 As Double,glength2 As DoubleDim x1_p As Double, y1_p As Double, z1_p As Double, port_distance As Double, L_p As Double, L_q As DoubleDim x0_q As Double, y0_q As Double, z0_q As Double, center_pointx1 As Double, center_pointx2 As DoubleDim x1_q As Double, y1_q As Double, z1_q As Double, center_pointy1 As Double, center_pointy2 As DoubleDim center_pointz1 As Double, center_pointz2 As Double, portlength_mean As DoubleDim tuningC_flag As Boolean'DSDim mws_block_port_position_x As Long, mws_block_port_position_y As LongDim mws_block_center_position_x As Long, mws_block_center_position_y As Long, make_abs As StringDim x_offset As Integer, y_offset As Integer, size_offset As IntegerDim blockname_variable As String, rel_x_pos As Double, rel_y_pos As Double, rot_angle As Double Dim differential_flag As Boolean, orientation As StringBegin Dialog UserDialog 390,161,"Compensate L and C for Discrete/Face Ports",.Dialogfunc ' %GRID:10,7,1,1CheckBox 30,15,170,14,"Include Capacitances",.add_capsCheckBox 30,35,210,14,"Create Link-Lines in CST-DS",.CreateLinksCheckBox 30,55,220,14,"Differential Ports and Blocks",.Diff_ports_blocksCheckBox 30,75,210,14,"Tuning Caps instead of Ports",.tuningCCheckBox 30,95,210,14,"Consider mutual Portcoupling",.port_couplingCheckBox 30,115,140,14,"Create Report",.reportGroupBox 270,7,100,63,"Solver-Type",.Group1OptionGroup .solver_typeOptionButton 290,28,70,21,"!T",.OptionButton1OptionButton 290,49,70,14,"!F",.OptionButton2OKButton 30,133,100,21CancelButton 140,133,90,21End DialogDim dlg As UserDialog' set dialog defaultsdlg.Createlinks = 1 : dlg.diff_ports_blocks = 0 : dlg.report = 0 : dlg.add_caps = 1' 0 = no 1 = yesdlg.solver_type = 0 ' 0 = !Tdlg.tuningC= 0If (Dialog(dlg) = 0) Then Exit All 'do the dialogIf dlg.diff_ports_blocks = 1 Thendifferential_flag= TrueElsedifferential_flag=FalseEnd IfIf dlg.tuningC = 1 ThentuningC_flag= TrueElsetuningC_flag=FalseEnd Ifsize_offset = 200 'position offset for drawing the elementsTotal_Nr_of_Discrete_Ports = 0' search for all ports in the MWS sectionport_name = "Ports\"get_all_child_names port_name,ListPortArray(),PortArrayLengthFor index_p = 0 To PortArrayLength-1port_index = Mid(ListPortArray(index_p),5,Len(ListPortArray(index_p))-4 ) '"portx" -> "x"If Port.getType(port_index) = "Discrete" Then 'find all discr. portsReDim Preserve Discrete_Port_List(Total_Nr_of_Discrete_Ports)Discrete_Port_List(Total_Nr_of_Discrete_Ports) = CStr(port_index)Total_Nr_of_Discrete_Ports=Total_Nr_of_Discrete_Ports+1Else 'wg portReDim Preserve Discrete_Port_List(Total_Nr_of_Discrete_Ports)Discrete_Port_List(Total_Nr_of_Discrete_Ports) = CStr(-port_index) 'wg-port: indicated as neg number!Total_Nr_of_Discrete_Ports=Total_Nr_of_Discrete_Ports+1End IfNext'add text to a report-fileoutput_string = "Total Number of Ports : " + CStr(Total_Nr_of_Discrete_Ports)+ vbCrLf ' redim the arrays for ind L and couplings K:ReDim K_array (0 To Total_Nr_of_Discrete_Ports-1, 0 To Total_Nr_of_Discrete_Ports-1)ReDim L_array (0 To Total_Nr_of_Discrete_Ports-1)'Loop over all Ports --------------------------------------------------------------------------For index_p = 0 To Total_Nr_of_Discrete_Ports-1If CInt(Discrete_Port_List(index_p)) > 0 Then 'consider only discrete ports for deembedding- computationPort.GetFacePortSize(Discrete_Port_List(index_p), face_port_dir1, face_port_dir2 ) '' width, length of face portfaceport_area = Port.GetFacePortArea(Discrete_Port_List(index_p) ) 'if no faceport : area = 0If faceport_area > 0 Then ' FACE-Port'check if dimensions are zeroIf face_port_dir1 = 0 Then 'widthIf face_port_dir2 = 0 Thenface_port_dir2=DiscretePort.getlength (Discrete_Port_List(index_p)) 'take the length via dis-port vba commandIf face_port_dir2 = 0 Then ' portlength = 0 !MsgBox "Face-Port inconsistencies at Port Nr. "+ cstr(Discrete_Port_List(index_p)) + " , check length of port !"Exit AllEnd Ifface_port_dir1 = faceport_area / face_port_dir2 'assume rectangular shaped faceport Elseface_port_dir1 = faceport_area / face_port_dir2 ' assuming rect faceports....A = w*h End IfElseIf face_port_dir2 = 0 Then 'portlength = 0!If face_port_dir1 = 0 ThenMsgBox "Face-Port inconsistencies at Port Nr. "+ cstr(Discrete_Port_List(index_p)) + " !"Exit AllElseface_port_dir2 = faceport_area / face_port_dir1 ' assuming rect faceports....A = w*h End IfEnd Ifface_port = True ' face portElseface_port = False ' ordinary discrete portEnd If'If !F Solver and Hex-Mesh is used , then switch to dis-port !!!!!!!!!!!!If dlg.solver_type = 1 And Mesh.GetMeshType = "PBA" Then ' solver_type= 1 = !FEnd IfSelect Case Mesh.GetMeshTypeCase "PBA" 'hexa-meshIf face_port Thenoutput_string = output_string+ vbCrLf+ " Face Port "+CStr(Discrete_Port_List(index_p))+ " (Hexa-Mesh)"+vbCrLfElseoutput_string = output_string+ vbCrLf+ " Edge Port "+CStr(Discrete_Port_List(index_p))+ " (Hexa-Mesh)"+vbCrLfEnd Ifoutput_string = output_string+ "Port Impedance = "+ CStr(Port.GetLineImpedance (Discrete_Port_List(index_p),1) )+" Ohm "If face_port Thenplength = face_port_dir2Elseplength=DiscretePort.getlength (Discrete_Port_List(index_p))End Ifglength= DiscretePort.getgridlength ( Discrete_Port_List(index_p))output_string = output_string+ "Gridlength= "+CStr( glength )+ " PortLength= "+CStr(plength)+ _" Deviation= "+ CStr( Format( (100*(glength-plength)/plength),"###0.##") )+ " % "+vbCrLfDiscretePort.GetElementDirIndex (Discrete_Port_List(index_p),long_ref_dir, long_ref_index) x= Mesh.getxpos(long_ref_index)y= Mesh.getypos(long_ref_index)z= Mesh.getzpos(long_ref_index)output_string = output_string+ "Source Center-location "+ CStr(x)+ " / "+CStr(y) + " / "+CStr(z)'************ search -density for gridpoints'delta = plength/100 'search increment to find next mesh index, 100 = 1% of Port-lengthdelta = Mesh.GetMinimumEdgeLength/2 'new methodN_max_searches = CInt(2*Mesh.GetMaximumEdgeLength/Mesh.GetMinimumEdgeLength)'************ end of search-densityIf long_ref_dir = 2 Then '(orientation in z)search_for_xlower_x_upper (delta, long_ref_index, x_upper, x_lower)search_for_ylower_y_upper (delta, long_ref_index, y_upper, y_lower)output_string = output_string+ " Orientation = z"+vbCrLfoutput_string = output_string+ "LocationMeshlines X: "+ CStr(x_lower) + "/ center "+ CStr(Mesh.getxpos(long_ref_index)) + " /"+ CStr(x_upper)+vbCrLfCStr(Mesh.getypos(long_ref_index)) + "/ "+ CStr(y_upper)'effective radiusIf face_port Thenwire_radius = face_port_dir1/2 ' half of width of faceportElsewire_radius = (Abs(x_upper-x_lower)+ Abs(y_upper-y_lower))/(4*Exp(1)^2) 'mean value radiusEnd Ifoutput_string = output_string+ vbCrLf+"Wire radius = "+CStr(wire_radius)'Formula für L of a straight wire:' inner LL_i = Units.GetGeometryUnitToSI()*plength*4*pi*1e-7/(8*pi)'L_a = Units.GetGeometryUnitToSI()*plength*2*1e-7*(Log(2*plength/wire_radius)-1)L_a = compute_L_a (wire_radius, plength)output_string = output_string+ " L_i= "+CStr (L_i*1e9)+" L_a = "+CStr (L_a*1e9)+ " nH" + vbCrLf'------ capacitance of discrete port z ------If dlg.add_caps = 1 Thensource_start_point= Mesh.getzpos(long_ref_index)DiscretePort.GetElement2ndIndex (Discrete_Port_List(index_p), long_ref_index2 )source_end_point = Mesh.getzpos(long_ref_index2)source_length = Abs(source_end_point-source_start_point)port_onearmlength = (plength-source_length)/2C_port=Units.GetGeometryUnitToSI()*compute_C(2*wire_radius,port_onearmlength,source_length/2) If face_port ThenC_port = C_port/correction_factor_face_ports(wire_radius,port_onearmlength,source_length/2)ElseC_port = C_port/correction_factor_dis_ports(wire_radius,port_onearmlength,source_length/2) End Ifoutput_string = output_string+ " Port_Capacitance = "+CStr (C_port*1e12)+ " pF" + " Gap-length: " + cstr(source_length) +vbCrLfEnd If'---------- end cap z ----------------------End If ' orientation z.....If long_ref_dir = 0 Then '(orientation in x)search_for_zlower_z_upper (delta, long_ref_index, z_upper, z_lower)output_string = output_string+ " Orientation = x"+vbCrLfoutput_string = output_string+ "LocationMeshlines Z: "+CStr(z_lower) + "/ center "+ CStr(Mesh.getzpos(long_ref_index)) + " /"+ CStr(z_upper)+vbCrLfoutput_string = output_string+ "LocationMeshlines Y: "+CStr(y_lower) + "/ center "+ CStr(Mesh.getypos(long_ref_index)) + "/ "+ CStr(y_upper)'effective radiusIf face_port Thenwire_radius = face_port_dir1/2 ' half of width of faceportElsewire_radius = (Abs(z_upper-z_lower)+ Abs(y_upper-y_lower))/(4*Exp(1)^2) 'mean value radiusEnd Ifoutput_string = output_string+ vbCrLf+"Wire radius = "+CStr(wire_radius)'Formula für L of a straight wire:' inner LL_i = Units.GetGeometryUnitToSI()*plength*4*pi*1e-7/(8*pi)'L_a = Units.GetGeometryUnitToSI()*plength*2*1e-7*(Log(2*plength/wire_radius)-1)L_a = compute_L_a (wire_radius, plength)output_string = output_string+ " L_i= "+CStr (L_i*1e9)+" L_a = "+CStr (L_a*1e9)+ " nH"+vbCrLf'------ capacitance of discrete port x ------If dlg.add_caps = 1 Thensource_start_point= Mesh.getxpos(long_ref_index)DiscretePort.GetElement2ndIndex (Discrete_Port_List(index_p), long_ref_index2 )source_end_point = Mesh.getxpos(long_ref_index2)source_length = Abs(source_end_point-source_start_point)port_onearmlength = (plength-source_length)/2C_port=Units.GetGeometryUnitToSI()*compute_C(2*wire_radius,port_onearmlength,source_length/2) If face_port ThenC_port = C_port/correction_factor_face_ports(wire_radius,port_onearmlength,source_length/2) ElseC_port = C_port/correction_factor_dis_ports(wire_radius,port_onearmlength,source_length/2) End Ifoutput_string = output_string+ " Port_Capacitance = "+CStr (C_port*1e12)+ " pF" + " Gap-length: " + cstr(source_length)+ vbCrLfEnd If'---------- end cap x ----------------------End If ' orientation x.....search_for_zlower_z_upper (delta, long_ref_index, z_upper, z_lower)search_for_xlower_x_upper (delta, long_ref_index, x_upper, x_lower)output_string = output_string+ " Orientation = y"+vbCrLfoutput_string = output_string+ "LocationMeshlines Z: "+CStr(z_lower) + "/ center "+ CStr(Mesh.getzpos(long_ref_index)) + " /"+ CStr(z_upper)+vbCrLfoutput_string = output_string+ "LocationMeshlines X: "+CStr(x_lower) + "/ center "+ CStr(Mesh.getxpos(long_ref_index)) + "/ "+ CStr(x_upper)'effective radiusIf face_port Thenwire_radius = face_port_dir1/2 ' half of width of faceportElsewire_radius = (Abs(z_upper-z_lower)+ Abs(x_upper-x_lower))/(4*Exp(1)^2) 'mean value radiusEnd Ifoutput_string = output_string+ vbCrLf+"Wire radius = "+CStr(wire_radius)'Formula für L of a straight wire:' inner LL_i = Units.GetGeometryUnitToSI()*plength*4*pi*1e-7/(8*pi)L_a = compute_L_a (wire_radius, plength)output_string = output_string+ " L_i= "+CStr (L_i*1e9)+" L_a = "+CStr (L_a*1e9)+ " nH"+vbCrLf'------ capacitance of discrete port y ------If dlg.add_caps = 1 Thensource_start_point= Mesh.getypos(long_ref_index)DiscretePort.GetElement2ndIndex (Discrete_Port_List(index_p), long_ref_index2 )source_end_point = Mesh.getypos(long_ref_index2)source_length = Abs(source_end_point-source_start_point)port_onearmlength = (plength-source_length)/2C_port=Units.GetGeometryUnitToSI()*compute_C(2*wire_radius,port_onearmlength,source_length/2) If face_port ThenC_port = C_port/correction_factor_face_ports(wire_radius,port_onearmlength,source_length/2) ElseC_port = C_port/correction_factor_dis_ports(wire_radius,port_onearmlength,source_length/2) End Ifoutput_string = output_string+ " Port_Capacitance = "+CStr (C_port*1e12)+ " pF" + " Gap-length: " + cstr(source_length) +vbCrLfEnd If'---------- end cap y ----------------------End If ' orientation y.....Case "Tetrahedral" ' "tetmesh"If face_port Thenoutput_string = output_string+ vbCrLf+ "Face-Port "+CStr(Discrete_Port_List(index_p))+ " (Tetra-Mesh)" + vbCrLfElseoutput_string = output_string+ vbCrLf+ "Edge-Port "+CStr(Discrete_Port_List(index_p))+ " (Tetra-Mesh)"+ vbCrLfEnd Ifoutput_string = output_string+ "Port Impedance = "+ CStr(Port.GetLineImpedance (Discrete_Port_List(index_p),1) )+" Ohm "If face_port Thenplength = face_port_dir2 'length of portElseMsgBox " Discrete Ports using Tetra-Mesh are not supported at port # "+ CStr(Discrete_Port_List(index_p))'Exit AllEnd IfIf face_port Then'compute C_wires horizontally orientated, C effectively ZERO; set to a dummy-factor of 1e6 in length and radiusC_port=Units.GetGeometryUnitToSI()*compute_C_tetmesh_new(face_port_dir1*0.000001,face_port_dir1/10 0000,plength/2) 'diameter=1%L, Length, heigth above groundElseC_port =0End Ifoutput_string = output_string+ " Face-Port_Capacitance = "+CStr (C_port*1e12)+ " pF" + " Wire-length: " + cstr(face_port_dir2) +vbCrLf'Formula L of a straight wire:'If face_port Thenwire_radius = face_port_dir1/2 'assumed: radius = half of port-widthL_i = Units.GetGeometryUnitToSI()*plength*4*pi*1e-7/(8*pi)L_a = compute_L_a (wire_radius, plength)ElseL_i = 0 : L_a=0End Ifoutput_string = output_string+ " L_i= "+CStr (L_i*1e9)+" L_a = "+CStr (L_a*1e9)+ " nH"+vbCrLfMsgBox "Meshtype unkown, not supported"Exit AllEnd SelectEnd If ' only discrete ports'Start of DesignStudio Implementation: draw neg. Ls + all external Ports + connections '--------------------------------------------------------------------------------------' get the port-position xy of the MWS BlockWith Block.name "MWSSCHEM1".SetDifferentialPorts differential_flagmws_block_port_position_x = .GetPortPositionX ( (index_p ) )mws_block_port_position_y = .GetPortPositionY ( (index_p ) )mws_block_center_position_x = .GetPositionXmws_block_center_position_y = .GetPositionYEnd Withrel_x_pos = mws_block_center_position_x - mws_block_port_position_xrel_y_pos = mws_block_center_position_y - mws_block_port_position_y'compute the orientation of the Ls; either left / right /up /downIf Abs(rel_x_pos) >= Abs(rel_y_pos) Then 'horizontal orientatedIf rel_x_pos <0 Thenx_offset = size_offset : y_offset = 0 : rot_angle = 0 : orientation="R" 'to the rightElsex_offset = - size_offset : y_offset = 0 : rot_angle = 180 : orientation="L" 'to the leftEnd IfEnd IfIf Abs(rel_x_pos) < Abs(rel_y_pos) Then ' vertical orientatedIf rel_y_pos <0 Thenx_offset = 0 : y_offset = size_offset : rot_angle = 90 : orientation="D" ' downElsex_offset = 0 : y_offset = - size_offset : rot_angle = -90 : orientation="U" ' upEnd IfEnd If'Draw the neg. inductances (Block)If CInt(Discrete_Port_List(index_p)) > 0 Then 'only for discr. portsDS.storeparameter(blockname_variable ,Format(-1.*(L_i+L_a)*Units.GetInductanceSIToUnit(),"###0.#######"))', blockname_variable +" L in "+ CStr(Units.GetInductanceUnit ()))With Block ' check existance.name "Port__L_"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithWith Block.Reset.type "CircuitBasic\Inductor".name "Port__L_"+CStr(Discrete_Port_List(index_p))Select Case orientationCase "L","R".position (mws_block_port_position_x +x_offset+index_p*x_offset/4 , mws_block_port_position_y+y_offset )Case "D".position (mws_block_port_position_x , mws_block_port_position_y + size_offset/2 +index_p*y_offset/4 )Case "U".position (mws_block_port_position_x , mws_block_port_position_y - size_offset/2 +index_p*y_offset/4 )End Select.create.Rotate (rot_angle).SetDoubleProperty ("Inductance", blockname_variable )End WithEnd If'Draw the neg. capacitances (Block)If dlg.add_caps = 1 ThenIf CInt(Discrete_Port_List(index_p)) > 0 Then 'only for discr. portsblockname_variable = "Port_C_"+CStr(Discrete_Port_List(index_p))DS.storeparameter(blockname_variable ,Format(-1.*C_port*Units.GetCapacitanceSIToUnit(),"###0.#######"))', blockname_variable +" C in "+ CStr(Units.GetCapacitanceUnit ()))With Block ' check existance.name "Port__C_"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithWith Block.type "CircuitBasic\Capacitor".name "Port__C_"+CStr(Discrete_Port_List(index_p))Select Case orientationCase "L","R".position (mws_block_port_position_x +1.5*x_offset+index_p*x_offset/4 , mws_block_port_position_y+y_offset +size_offset/2 )Case "D".position (mws_block_port_position_x +1*y_offset +size_offset+index_p*x_offset/4, mws_block_port_position_y+y_offset + size_offset+index_p*y_offset/4 )Case "U".position (mws_block_port_position_x -1*y_offset +size_offset+index_p*x_offset/4, mws_block_port_position_y+y_offset - size_offset+index_p*y_offset/4 )End Select.create.Rotate (rot_angle+90).SetDoubleProperty ("Capacitance", blockname_variable )End WithWith Block ' check existance.name "GND__"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithIf Not differential_flag ThenWith Block.Reset.Type ("Ground").name "GND__"+CStr(Discrete_Port_List(index_p))Select Case orientationCase "L","R".position (mws_block_port_position_x +1.5*x_offset+index_p*x_offset/4 , mws_block_port_position_y+y_offset +size_offset )Case "D".position (mws_block_port_position_x +2*y_offset +size_offset +index_p*x_offset/4, mws_block_port_position_y+y_offset + size_offset*2 +index_p*y_offset/4 )'.rotate (90)Case "U".position (mws_block_port_position_x -2*y_offset +size_offset +index_p*x_offset/4, mws_block_port_position_y+y_offset - 0.2*size_offset )End Select.CreateEnd WithEnd IfEnd IfIf dlg.add_caps = 0 ThenWith Block ' check existance.name "Port__C_"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithWith Block ' check existance.name "GND__"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithEnd If'If tuningC_flag Then 'not' draw the EXTERNAL port ----------------------------With ExternalPortmake_abs = CStr(Abs(CInt(Discrete_Port_List(index_p)))).Number make_absIf .doesexist Then.deleteEnd IfEnd WithWith ExternalPortmake_abs = CStr(Abs(CInt(Discrete_Port_List(index_p)))).Number make_abs 'Discrete_Port_List(index_p)If CInt(Discrete_Port_List(index_p)) > 0 Then 'only for discr. ports.create.SetDifferential differential_flag.SetFixedImpedance( True).SetImpedance CStr(Port.GetLineImpedance (Discrete_Port_List(index_p),1) ).position(mws_block_port_position_x+(Total_Nr_of_Discrete_Ports-1)*x_offset,mws_block_port_position_y+( Total_Nr_of_Discrete_Ports-1)*y_offset )Else 'wg ports.position (mws_block_port_position_x+0.5*x_offset,mws_block_port_position_y+0.5*y_offset ) .create.SetDifferential differential_flagEnd IfEnd With' End If'---------------------------------------------------------------'c instead of portsIf tuningC_flag ThenIf CInt(Discrete_Port_List(index_p)) > 0 Then 'only for discr. portsblockname_variable = "dC_"+CStr(Discrete_Port_List(index_p))DS.storeparameter(blockname_variable ,Format(0*Units.GetCapacitanceSIToUnit(),"###0.#######"))', blockname_variable +" C in "+ CStr(Units.GetCapacitanceUnit ()))With Block ' check existance.name "d__C_"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithWith Block.Reset.type "CircuitBasic\Capacitor".name "d__C_"+CStr(Discrete_Port_List(index_p))Select Case orientationCase "L","R".position (mws_block_port_position_x +3*x_offset+index_p*x_offset/4 , mws_block_port_position_y+y_offset +size_offset/2 )Case "D".position (mws_block_port_position_x +1*y_offset +size_offset+index_p*x_offset/4, mws_block_port_position_y+y_offset + 2*size_offset+index_p*y_offset/4 )Case "U".position (mws_block_port_position_x -1*y_offset +size_offset+index_p*x_offset/4, mws_block_port_position_y+y_offset - 2*size_offset+index_p*y_offset/4 )End Select.create.Rotate (rot_angle+90).SetDoubleProperty ("Capacitance", blockname_variable )End With' gnd for insteadWith Block ' check existance.name "dGND__"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithIf Not differential_flag ThenWith Block.Reset.Type ("Ground").name "dGND__"+CStr(Discrete_Port_List(index_p))Select Case orientationCase "L","R".position (mws_block_port_position_x +3*x_offset+index_p*x_offset/4 , mws_block_port_position_y+y_offset +size_offset/1 )Case "D".position (mws_block_port_position_x +2*y_offset +size_offset +index_p*x_offset/4, mws_block_port_position_y+y_offset + size_offset*2 +index_p*y_offset/4 )'.rotate (90)Case "U".position (mws_block_port_position_x -2*y_offset +size_offset +index_p*x_offset/4, mws_block_port_position_y+y_offset - 0.2*size_offset )End Select.CreateEnd WithEnd IfEnd IfElseWith Block ' check existance.name "d__C_"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithWith Block.name "dGND__"+CStr(Discrete_Port_List(index_p))If .doesexist Then.deleteEnd IfEnd WithEnd If' end instead'--------------------------'draw the connection linesIf dlg.Createlinks = 1 ThenIf CInt(Discrete_Port_List(index_p)) > 0 Then 'only for discr. portsWith Link'Links between ext.port and L.Reset.setsourceportfromexternalport (Discrete_Port_List(index_p),False).settargetportfromblockport ("Port__L_"+CStr(Discrete_Port_List(index_p)),"2", False).createEnd WithWith Link 'between L and MWS-ports.Reset.SetSourcePortFromBlockPort("MWSSCHEM1", Discrete_Port_List (index_p+0), False) ' DS_port_index,False.settargetportfromblockport ("Port__L_"+CStr(Discrete_Port_List(index_p)),"1",False).createEnd WithIf dlg.add_caps = 1 ThenWith Link 'Links between C and L.Reset.setsourceportfromblockport ("Port__L_"+CStr(Discrete_Port_List(index_p)),"2", False)Select Case orientationCase "L".settargetportfromblockport ("Port__C_"+CStr(Discrete_Port_List(index_p)),"2", False) Case "R".settargetportfromblockport ("Port__C_"+CStr(Discrete_Port_List(index_p)),"1", False) Case "D".settargetportfromblockport ("Port__C_"+CStr(Discrete_Port_List(index_p)),"2", False) Case "U".settargetportfromblockport ("Port__C_"+CStr(Discrete_Port_List(index_p)),"1", False) End Select.createEnd WithEnd IfIf dlg.add_caps = 1 ThenIf Not differential_flag ThenWith Link 'between C and ground.Reset.SetSourcePortFromBlockPort("GND__"+Cstr(Discrete_Port_List(index_p)),"GND",False)Select Case orientationCase "L","D".settargetportfromblockport("Port__C_"+CStr(Discrete_Port_List(index_p)),"1",False) Case "R","U".settargetportfromblockport("Port__C_"+CStr(Discrete_Port_List(index_p)),"2",False) End Select.createEnd WithEnd IfEnd If。